spring-test

How to drop in-memory h2db between Spring Integration tests?

送分小仙女□ 提交于 2020-02-02 03:06:28
问题 I am using Liquibase in my Spring web application. I have a bunch of entities with hundreds of tests for REST APIs in the integration tests for each entity like User, Account, Invoice, License etc. All of my integration tests pass when run by class but a lot of them fail when ran together using gradle test . It is very likely there is data collision between the tests and I am not interested in spending time to fix clean up data as of now. I prefer dropping the DB and context after every class

@IfProfileValue vs @ActiveProfiles in the context of Spring test

a 夏天 提交于 2020-01-29 12:59:18
问题 I am in reference to Spring test and the following annotations: @IfProfileValue @ActiveProfiles I currently use @ActiveProfiles in my application and I recently discovered the existence of the @IfProfileValue annotation which seems to provide similar functionnality. Can someone please explain what the differences are between those two annotations perhaps by providing usage examples that would contrast the two? 回答1: As stated in the Javadoc, @IfProfileValue is used to indicate that a test is

Error testing spring boot 1.4 application

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-23 06:50:08
问题 I have very simple spring boot 1.4 application with one rest controller. When i tried to test the context loading of this i am getting error like below :- 13:29:03.623 [main] DEBUG o.s.t.c.j.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 13:29:03.628 [main] DEBUG o.s.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test

Spring boot test configuration

为君一笑 提交于 2020-01-22 17:21:55
问题 I have a spring boot application with main class like below: @SpringBootApplication public class Application { public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } } Now I want to test my services and created a base test class: @SpringApplicationConfiguration(Application.class) public abstract class TestBase { } When I run my test I get exception: Caused by: java.lang.IllegalArgumentException: Can not load an ApplicationContext with a

Spring boot test configuration

拟墨画扇 提交于 2020-01-22 17:21:06
问题 I have a spring boot application with main class like below: @SpringBootApplication public class Application { public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } } Now I want to test my services and created a base test class: @SpringApplicationConfiguration(Application.class) public abstract class TestBase { } When I run my test I get exception: Caused by: java.lang.IllegalArgumentException: Can not load an ApplicationContext with a

How configure correctly @RunWith(Parameterized.class) + SpringClassRule + SpringMethodRule with a custom @Rule?

谁说胖子不能爱 提交于 2020-01-22 16:38:07
问题 I am working with Spring Framework 4.3.x and JUnit 4, I have the following structure @Transactional @WebAppConfiguration @RunWith(Parameterized.class) @ContextConfiguration(classes={RootApplicationContext.class, ServletApplicationContext.class}) @TestExecutionListeners(listeners={LoggingTestExecutionListener.class}, mergeMode=MergeMode.MERGE_WITH_DEFAULTS) public class CompleteTest { @ClassRule public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule(); @Rule public final

Spring asynch method integration test fails

白昼怎懂夜的黑 提交于 2020-01-16 20:19:26
问题 I created an integration test for asynchronous rest controller method. Which looks like: @Test public void shouldHandleRequestsAsynchronously() throws Exception { MvcResult mvcResult = this.mockMvc.perform(get("/api/reports/daily?startDate=2004-04-13&endDate=2005-04-13")) .andExpect(request().asyncStarted()) .andReturn(); this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].totalDistance", equalTo(100))) .andExpect(jsonPath("$[0].totalPrice",

Spring asynch method integration test fails

安稳与你 提交于 2020-01-16 20:19:09
问题 I created an integration test for asynchronous rest controller method. Which looks like: @Test public void shouldHandleRequestsAsynchronously() throws Exception { MvcResult mvcResult = this.mockMvc.perform(get("/api/reports/daily?startDate=2004-04-13&endDate=2005-04-13")) .andExpect(request().asyncStarted()) .andReturn(); this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].totalDistance", equalTo(100))) .andExpect(jsonPath("$[0].totalPrice",

Spring, Failed to load ApplicationContext in tests

旧巷老猫 提交于 2020-01-16 03:53:05
问题 I have following web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener <

No JSON content (comes up null) from MockMvc Test using Spring MVC and Mockito

徘徊边缘 提交于 2020-01-15 12:00:51
问题 Have a codebase which uses SpringMVC 4.0.3.RELEASE for Restful Web Services. Codebase contains a fully functional Restful Web Service which I can verify works using postman and curl. However, when trying to write a unit test for the particular Restful Web Service using MockMvc, I become blocked with trying to obtain the JSON content from the unit test. Am wondering if its a config issue or an issue where I am not creating a fake object correctly (since this doesn't rely on tomcat and is