Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it exactly mean to use @DirtiesContext annotation on a class?

Tags:

java

junit

spring

I have been working with Spring and I came across the @DirtiesContext annotation provided by spring. Using it on every method makes sense when you want to refresh the application context before running each method(of course at the expense of performance) but what does it exactly mean to annotate a test class with @DirtiesContext? An example would be really helpful.

like image 269
Kunal gupta Avatar asked Jan 22 '26 04:01

Kunal gupta


1 Answers

If you annotate a test class with @DirtiesContext, it will remove the application context after the tests are run. There is a lot more explaining in this article: DirtiesContext annotation

like image 129
Raul Cuth Avatar answered Jan 23 '26 20:01

Raul Cuth