junit5

spring boot test junit null pointer exception

萝らか妹 提交于 2021-02-05 06:09:46
问题 im new on this of unit tests, so im trying to code the unit test for my service, right now i have this class package com.praxis.topics.service; import com.praxis.topics.exception.EntityNotFoundException; import com.praxis.topics.model.Topic; import com.praxis.topics.model.enums.Status; import com.praxis.topics.repository.TopicRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java

How to prepare a nested data structure for a data-driven test in Karate?

血红的双手。 提交于 2021-02-02 09:08:47
问题 I currently use junit5, wiremock and restassured for my integration tests. Karate looks very promising, yet I am struggling with the setup of data-driven tests a bit as I need to prepare a nested data structures which, in the current setup, looks like the following: abstract class StationRequests(val stations: Collection<String>): ArgumentsProvider { override fun provideArguments(context: ExtensionContext): java.util.stream.Stream<out Arguments>{ val now = LocalDateTime.now() val samples =

How to prepare a nested data structure for a data-driven test in Karate?

﹥>﹥吖頭↗ 提交于 2021-02-02 09:08:16
问题 I currently use junit5, wiremock and restassured for my integration tests. Karate looks very promising, yet I am struggling with the setup of data-driven tests a bit as I need to prepare a nested data structures which, in the current setup, looks like the following: abstract class StationRequests(val stations: Collection<String>): ArgumentsProvider { override fun provideArguments(context: ExtensionContext): java.util.stream.Stream<out Arguments>{ val now = LocalDateTime.now() val samples =

Better way to set testcontainer properties from default applicaton.yml in springboottest

流过昼夜 提交于 2021-01-29 14:16:04
问题 I am using posgresql testcontainer in springboottest. As I have multiple tests involving this testcontainer, hence I have used static testcontainer which will be invoked once for all tests of 1 junit class and shutdown after all tests are executed. This I have implemented using ParameterResolver, BeforeEachCallback. Problem with this approach is that datasource metadata like jdbc-url, db name , host , port configured in default application.yml is not used directly in testcontainer properties,

Spring Boot 2.3.1, JUnit 5, Maven 3.6.3 - Maven lifecycle “test” does not run test suite

可紊 提交于 2021-01-29 10:08:45
问题 pom.xml: ... <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-runner</artifactId> <version>1.7.0-M1</version> <scope>test</scope> </dependency> ... In <build> only is used: <plugin> <groupId

How to test repository with junit5 and testcontainers?

六月ゝ 毕业季﹏ 提交于 2021-01-29 08:12:19
问题 I have a sample project in which I experiment with different technologies. I have the following setup: Spring Boot 2.3.4.RELEASE Flyway 7.0.1 Testcontainers 1.15.0-rc2 Junit 5.7.0 How can I test the Repository layer with testcontainer-junit5? Example of code I have now for CompanyRepositoryTest.java : @ExtendWith(SpringExtension.class) @Testcontainers public class CompanyRepositoryTest { @Autowired private CompanyRepository companyRepository; @Container public MySQLContainer mysqlContainer =

How to pass a Input and Expected file name dynamically for BeforeAll Method | Junit 5

血红的双手。 提交于 2021-01-29 06:08:02
问题 I have Implemented a test cases to check the Input and expected Json files are same. @BeforeAll static void setUp() throws IOException { inputList = readInput(CommonTestConstants.FilePath + "/Input1.json"); expectedList = readExpected(CommonTestConstants.FilePath + "/Expected1.json"); assertEquals("Checking size of both list", inputList.size(), expectedList.size()); } static Stream<Arguments> Arguments() { return IntStream.range(0, inputList.size()) .mapToObj(i -> Arguments.of(inputList.get(i

JUnit5 Jupiter test terminated in IntelliJ

情到浓时终转凉″ 提交于 2021-01-28 14:24:44
问题 When I run the my unit tests, they immediatly are being terminated. However no logging is presented. (only 'Failed to start' and 'Process finished with exit code 255'). Tests worked before... JUnit 4 does not give me this problem. Test do run succesfully in Maven. I use JUnit5 Jupiter and IntelliJ IDEA 2020.1 (Ultimate Edition). Anyone any thoughts? 回答1: I just had the same issue. The single thing that fixed this - and which I could reproduce - is this: don't .close() System.out (or System

How to register Spring Context Events for current test ApplicationContext at runtime

别说谁变了你拦得住时间么 提交于 2021-01-27 17:53:36
问题 Background : My goal is to collect various timestamps while executing JUnit 5 tests in a Spring environment to create a statistic of the durations of the different tasks. (Repository for reference) Because I can't touch the actual test code, I have to register callbacks like the ContextRefreshedEvent from within my JUnit Jupiter extension. Currently I am registering these callbacks in a Spring configuration object and hope that this is found by some component scan in the test application. As

JUnit java.lang.NoSuchMethodError: org.junit.jupiter.api.extension.ExtensionContext.getRequiredTestInstances()

泄露秘密 提交于 2021-01-27 07:15:30
问题 I was creating some JUnit test cases for my project app (Spring Boot) and encountered the following error stack below when I run my JUnit test cases: java.lang.NoSuchMethodError: org.junit.jupiter.api.extension.ExtensionContext.getRequiredTestInstances()Lorg/junit/jupiter/api/extension/TestInstances; at org.mockito.junit.jupiter.MockitoExtension.beforeEach(MockitoExtension.java:141) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeEachCallbacks$0