spring-boot-test

Spring boot integration test fails with Neo4j

安稳与你 提交于 2019-12-23 02:19:21
问题 I am new to spring boot. I use Spring Boot 1.5.1 GA and Neo4j starter of spring boot. I tried to create my very first integration test to whether I can insert a new object into the graph database. Here is my test class: package hu.bookandwalk; import static org.junit.Assert.assertEquals; import java.time.LocalDateTime; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.neo4j.ogm.testutil.TestServer; import org

@ComponentScan in application class breaks @WebMvcTest and @SpringBootTest

元气小坏坏 提交于 2019-12-22 13:50:14
问题 I am creating tests with @WebMvcTest annotation and found that if I have a @ComponentScan annotation in the application class it will break the expected behavior of the tests. According to the WebMvcTest javadoc: Using this annotation will disable full auto-configuration and instead apply only configuration relevant to MVC tests (i.e. @Controller , @ControllerAdvice , @JsonComponent Filter , WebMvcConfigurer and HandlerMethodArgumentResolver beans but not @Component , @Service or @Repository

Spring boot testing of a rest client using @RestClientTest

China☆狼群 提交于 2019-12-21 04:12:42
问题 I am using spring boot 1.5.8 and want to test my client: @Component public class RestClientBean implements RestClient { private Map<String, RestTemplate> restTemplates = new HashMap<>(); @Autowired public RestClientBean(RestTemplateBuilder builder, SomeConfig conf) { restTemplates.put("first", builder.rootUri("first").build(); restTemplates.put("second", builder.rootUri("second").build(); } } with the following test: @RunWith(SpringRunner.class) @RestClientTest(RestClient.class) public class

SpringApplicationConfiguration cannot be resolved in a Spring Boot test

梦想的初衷 提交于 2019-12-20 03:48:34
问题 I've generated a Spring Boot web application using Spring Initializr, using embedded Tomcat + Thymeleaf template engine, and package as an executable JAR file. Technologies used : Spring Boot 1.4.2.RELEASE, Spring 4.3.4.RELEASE, Thymeleaf 2.1.5.RELEASE, Tomcat Embed 8.5.6, Maven 3, Java 8. Now I want to implement a Test using the class SpringApplicationConfiguration , so I imported <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId>

Spring-boot application-test.properties

情到浓时终转凉″ 提交于 2019-12-19 03:07:30
问题 I am trying to unit test the spring-boot application using junit. I have placed the application-test.properties under src/test/resources. I have a ApplicationConfiguration Class which reads the application.properties. My test class looks like this @RunWith(SpringRunner.class) @SpringBootTest(classes=ApplicationConfiguration.class) @TestPropertySource(locations = "classpath:application-test.properties") @ActiveProfiles("test") public class TestBuilders { @Autowired private

Slow startup on spring integration test. Cause? Can't disable RabbitMQ

二次信任 提交于 2019-12-13 16:56:11
问题 I'm struggling in a performance problem on startup with my integration tests. I'm trying to mock the messaging of the system. To do that, I basically use @MockBean on my gateway and use @EnableAutoConfiguration(exclude = {RabbitAutoConfiguration.class}) . Example: @RunWith(SpringRunner.class) @SpringBootTest(classes = MyApplication.class) @WebAppConfiguration @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @ActiveProfiles("test") @EnableAutoConfiguration(exclude =

SpringBoot: how to run tests twice, with two different config files

家住魔仙堡 提交于 2019-12-13 03:19:04
问题 I am writing a SpringBoot application using a JMS MOM. My application supports two kinds of JMS: EMS and AMQ My application has many Junit Tests. Of course, whether I use EMS or AMQ the tests are exactly the same and the expected results are also exactly the same. The only difference is the configuration file used. @RunWith(SpringRunner.class) @TestPropertySource(locations="classpath:application.yaml") @ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class) public

The @PropertyMapping annotation @WebMvcTest cannot be used in combination with the @Component annotation @Configuration

China☆狼群 提交于 2019-12-13 00:52:34
问题 I have a Spring MVC test: @RunWith(SpringRunner.class) @WebMvcTest @Configuration public class InventoryControllerIntegrationTest { @MockBean private InventoryService inventoryService; @Autowired private MockMvc mockMvc; @Test public void shouldReturnInventory() throws Exception { this.mockMvc.perform(get("/inventory")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString("Hello World"))); } } And a corresponding controller. After running the test I get the

Unable to build Spring Boot project having datasource lookup from jndi

假装没事ソ 提交于 2019-12-13 00:16:56
问题 I am building an application in Spring Boot and deploying in JBoss AS. I have removed the embedded tomcat in pom.xml: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> For connecting to database, the project is running correctly when I am connecting via jdbc by providing the

@MockMvc does not work with validation annotated with @Valid

雨燕双飞 提交于 2019-12-12 16:33:06
问题 None of these solutions helped here: Spring mockMvc doesn't consider validation in my test. Added all of these dependencies, nothing helps. I use Spring Boot 2.1.2, pom.xml: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> </parent> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web<