#DirtiesContext not working as expected after upgrading to Spring Boot 2.2.2 - spring-boot

I am trying to upgrade my application from Spring Boot v2.1.8 to v2.2.2. However, after upgrading some tests start failing.
The pattern of failing tests strongly indicates that #DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD), applied on test class, is failing to clear context after each test case.
I am unable to narrow down further. Will appreciate any help.

I had the same issue today. With spring boot 2.2.7 not playing nice with Dirties context. In my case, I was using DBUnit to test and it wasn’t resetting the DB.
Adding this annotation fixed it for me:
#AutoConfigureTestDatabase(replace = Replace.ANY)

Related

SpringBootTest annotation doesn't work in maven build command

I add annotation SpringBootTest on my test class, it works very well in IDE(intellij), but when I run mvn test command, it seems SpringBootTest annotation doesn't work, because I didn't see spring context is initialized from logs and the auto-wired object is null. Does anyone know what might be wrong?
BTW, I use spring-boot 2.7.1
This is maven-surefire-plugin issue, spring boot 2.7.1 use junit5 while the maven-surefire-plugin I used doesn't support junit5. Upgrading maven-surefire-plugin can solve this problem

Spring context initialisation hangs when executing a test annotated with #SpringBootTest after a test annotated with #DataJpaTest

I think I've stumbled about a bug in either Spring, Spring Boot, Spring Data JPA or Spring Data ReST. When I execute a test annotated with #DataJpaTest before a test annotated with #SpringBootTest the initialisation of the application context of the Spring Boot test hangs. Unfortunately the minimal example to reproduce the issue is too large to be posted here, so have uploaded an example project reproducing the issue here.
I have the following questions
Is it a bug or is it a strange setup?
Is the bug already known? (I have been looking for error problems in GitHub and StackOverflow, but found nothing that fits)
If it is a bug in which project Spring Framework, Spring Boot, Spring Data Jpa or Spring Data ReST should I open a bug issue?
Thanks for your help.

How to prevent cucumber from hatching several SpringBoot context

I am using Cucumber + Spring Boot + Spring Cache
Every time Cucumber jumps from one Scenario Outline to the other, my Spring Boot context is rebuilt (I can see the Banner) and my Spring Cache is rebuild... which takes a lot of time.
I tried to add #DirtiesContext above the #SpringBootTest(Web) on the java steps class, that didn't helped.
How can I prevent Cucumber from refreshing the context on each and every Scenario?
Thanks
Upgrade your Cucumber to v5 and make sure you do not have #DirtiesContext any where in your spring configuration.
https://github.com/cucumber/cucumber-jvm/tree/master/spring

IllegalStateException at start up Spring JUnit test

I've made a simple Maven Spring REST project. (this one: https://spring.io/guides/gs/rest-service/)
Afterwards I made a simple JUnit test using MockMVC to test the REST functionality. In this case: does my code respond to /greeting?
When I run my test (using IntelliJ) I get this IllegalStateException.
How can I resolve this?
You're probably using incompatible versions of spring-test and spring-boot. spring-test calls SpringApplicationContextLoader.getResourceSuffixes (plural form) since v4.1.0.RC2. spring-boot's SpringApplicationContextLoader.getResourceSufffix (singular) throws that exception since v1.3.0.RC1.
You would have to either upgrade to spring-test >= 4.1.0 or downgrade to spring-boot < 1.3.0

Intellij spring boot integration

For some reason Intellij 13.1.3 doesn't detect the spring boot beans. Spring boot version is 1.1.1-Release. When i try to inject ObjectMapper in some component i get an error in the IDE "No bean of type ObjectMapper defined", however the application compiles and runs just fine and the ObjectMapper beans is visible in the /beans json.
I have added my application-context and my Application.java files to a spring facet and the IDE recognizes all my other beans that I manually defined, it just ignores the ones that come with Spring boot #EnableAutoConfiguration. Any idea how to solve that since its kinda tedious not to have the correct linking in the IDE and get errors all over the place. I would assume thats a common issue?
Thanks!
As an update for this answer: IntelliJ now supports Spring Boot. Must be at least R14. R15 is including some more integration.
Spring Boot is not supported yet, please watch http://youtrack.jetbrains.com/issue/IDEA-119230

Resources