spring-test

How to fix the null value response of RestTemplate.exchange in a Mockito Test?

点点圈 提交于 2021-02-08 23:38:20
问题 My Service class is below, followed by its test - @Service public class MyServiceImpl implements MyService { @Autowired private RestTemplate restTemplate; @Override public StudentInfo getStudentInfo(String name) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); HttpEntity entity = new HttpEntity(headers); StudentInfo student = null; URI uri = new URI("http:\\someurl.com"); ResponseEntity<String> responseEntity = restTemplate.exchange(uri,

@IfProfileValue not working with JUnit 5 SpringExtension

大城市里の小女人 提交于 2021-02-08 13:19:38
问题 I use junit5 with spring-starter-test, in order to run spring test I need to use @ExtendWith instead of @RunWith . However @IfProfileValue work with @RunWith(SpringRunner.class) but not with @ExtendWith(SpringExtension.class) , below is my code: @SpringBootTest @ExtendWith({SpringExtension.class}) class MyApplicationTests{ @Test @DisplayName("Application Context should be loaded") @IfProfileValue(name = "test-groups" , value="unit-test") void contextLoads() { } } so the contextLoads should be

@IfProfileValue not working with JUnit 5 SpringExtension

Deadly 提交于 2021-02-08 13:19:31
问题 I use junit5 with spring-starter-test, in order to run spring test I need to use @ExtendWith instead of @RunWith . However @IfProfileValue work with @RunWith(SpringRunner.class) but not with @ExtendWith(SpringExtension.class) , below is my code: @SpringBootTest @ExtendWith({SpringExtension.class}) class MyApplicationTests{ @Test @DisplayName("Application Context should be loaded") @IfProfileValue(name = "test-groups" , value="unit-test") void contextLoads() { } } so the contextLoads should be

Configuring base package for component scan in Spring boot test

人盡茶涼 提交于 2021-02-08 12:20:01
问题 When I launch my test with the following annotations: package com.hello.package.p1; @RunWith(SpringRunner.class) @DataMongoTest @SpringBootTest public class ClassATest { @Autowired Service1 serivce1; //fqn = com.hello.package.p1.Service1 @Autowired Service2 serivce2; //fqn = com.hello.package.p2.Service2 ...} package com.hello.package.p1; @ActiveProfiles("test") @SpringBootConfiguration public class MongoTestConfig { ... } service1 will be injected. But service2 will not, since it is not in

Configuring base package for component scan in Spring boot test

不打扰是莪最后的温柔 提交于 2021-02-08 12:17:58
问题 When I launch my test with the following annotations: package com.hello.package.p1; @RunWith(SpringRunner.class) @DataMongoTest @SpringBootTest public class ClassATest { @Autowired Service1 serivce1; //fqn = com.hello.package.p1.Service1 @Autowired Service2 serivce2; //fqn = com.hello.package.p2.Service2 ...} package com.hello.package.p1; @ActiveProfiles("test") @SpringBootConfiguration public class MongoTestConfig { ... } service1 will be injected. But service2 will not, since it is not in

Spring Batch - How to prevent database commits with jobLauncherTestUtils

大兔子大兔子 提交于 2021-02-07 12:55:50
问题 I have Spring Batch job that writes to the database (it has a step with a JpaItemWriter ). I have an integration test such as follows: @RunWith(SpringRunner.class) @SpringBootTest @ActiveProfiles("integrationTest") public class LoadApplicationTests { @Autowired private Job job; @Autowired private JobRepository jobRepository; @Autowired private JobLauncher jobLauncher; private JobLauncherTestUtils jobLauncherTestUtils; @Before public void setUp() throws IOException, java.text.ParseException,

Is it possible to cache Spring's Application Context between classes?

时光毁灭记忆、已成空白 提交于 2021-02-07 08:15:54
问题 I'm trying to improve the performance of the Spring integration tests of a project I'm working on. We're using Spring + Gradle + JUnit. With this configuration inside the build.gradle file: test { useJUnit() setForkEvery(0) setMaxParallelForks(1) } We're able to run all tests in a single JVM. Though I think this is the default behaviour. But I've been reading about Spring Test Context Caching and with this property in my application-test.yml: logging: level: org: springframework: test:

Is it possible to cache Spring's Application Context between classes?

馋奶兔 提交于 2021-02-07 08:05:34
问题 I'm trying to improve the performance of the Spring integration tests of a project I'm working on. We're using Spring + Gradle + JUnit. With this configuration inside the build.gradle file: test { useJUnit() setForkEvery(0) setMaxParallelForks(1) } We're able to run all tests in a single JVM. Though I think this is the default behaviour. But I've been reading about Spring Test Context Caching and with this property in my application-test.yml: logging: level: org: springframework: test:

Cucumber tags as TestNG group in QAF and Spring boot environment

时光总嘲笑我的痴心妄想 提交于 2021-01-28 08:58:21
问题 I have 4 tests in a feature file with 2 different tags @first and @then. I would like @first tests to run first with parallelism and @then tests to run after all @first tests finished, with parallelism too. The project is here : https://github.com/marcesso/qafTesting @CucumberOptions(plugin = {"com.qmetry.qaf.automation.cucumber.QAFCucumberPlugin", "pretty", "html:target"}, /*tags = {"@Ignore"},*/ features = {"src/test/resources/my/custom/packagename/testing"}) public class RunnerTest extends

SpringBootTest is connecting to database

眉间皱痕 提交于 2021-01-28 02:43:38
问题 I have a test that is testing parts of a spring application. It is using SpringRunner and the annotaion @SpringBootTest so it is starting a full spring server. Problem is that the test is being executed by a server that does not have access to the database, so I am getting a lot of connection timeouts that is slowing down the test. The connection issues in itself isn't really a problem as the tests are mocking the calls to the database, and so they are not relying on the connection being