简体   繁体   English

如何在 Intellij Idea 中的测试运行之间保持加载 spring 上下文?

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

Spring-test provides annotation for loading spring context during test runs. Spring-test提供了在测试运行期间加载 spring 上下文的注释。 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.例如,有一个org.springframework.test.context.junit4.SpringJUnit4ClassRunner junit runner 类和org.springframework.test.context.ContextConfiguration注释用于指定上下文加载。 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?例如,我完成了调试上下文加载,然后运行该上下文并开始在 intellij idea 中运行测试? Is that possible with Intellij Idea? Intellij Idea可以做到吗?

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.此外,所有扩展此类的类都将重用相同的上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM