Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How keep spring context loaded between test runs in Intellij Idea?

Spring-test provides annotation for loading spring context during test runs. For example there is a org.springframework.test.context.junit4.SpringJUnit4ClassRunner junit runner class and org.springframework.test.context.ContextConfiguration annotation for specify context loading. For integration tests context loading can be quite long and during debugging it is needed to run same test dozen times until it "lose" all it's errors. Is there a way to do so without loading context multiple times? For example I finished debugging context loading, then run that context and start running test in intellij idea? Is that possible with Intellij Idea?

like image 962
Cherry Avatar asked Jun 08 '16 08:06

Cherry


1 Answers

Long time ago without answer, which is strange, and this is very important to know because it can save a lot of resources and time.

If you have one class with annotation

@SpringBootTest
public class IntegrationTest

And you extend it to all your Test classes context will be loaded only once

public class ServiceIntegationTest extends IntegrationTest

All tests in this class will use same context. Also all classes that extend this class will reuse same context.

like image 92
mommcilo Avatar answered Oct 01 '22 23:10

mommcilo