简体   繁体   English

Spring Boot中的@IntegrationTest与“普通”单元测试一起运行时,手风琴测试失败

[英]@IntegrationTest in spring boot makes concordion tests fail when run in combination with 'normal' unit tests

I am using concordion for end to end testing my spring boot REST API. 我正在使用Concordion进行我的Spring Boot REST API的端到端测试。 I found that i could let the concordion test start up my spring application with the @IntegrationTest annotation. 我发现我可以使用@IntegrationTest批注让手风琴测试启动我的spring应用程序。 This works if i manually run 1 concorion test, or all concordion test.. But if i include regular unit test (without the @IntegrationTest), then the concordion tests will fail with an org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8080/myrestservice":Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect. 如果我手动运行1个concorion测试或所有conordion测试,这将起作用。但是,如果我包括常规单元测试(不带@IntegrationTest),则该conordion测试将失败,并出现org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8080/myrestservice":Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect. org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8080/myrestservice":Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect.

If i annotate my regular unit tests with the @IntegrationTest annotation, it all works. 如果我使用@IntegrationTest批注注释我的常规单元测试,则所有方法都可以使用。 But i would like to know if anyone knows a better way? 但是我想知道是否有人知道更好的方法?

edit: both my concordion tests and my unit tests have the following other annotations: 编辑:我的手风琴测试和单元测试都具有以下其他注释:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
    classes = Application.class,
    loader = SpringApplicationContextLoader.class)
@WebAppConfiguration

I guess you have a cached ApplicationContext shared across all your tests. 我猜您在所有测试中共享了一个缓存的ApplicationContext You can change the cache key by changing the configuration sources (eg add an empty TestConfiguration.class ) or by using a profile (eg `@ActiveProfiles("integration")). 您可以通过更改配置源(例如,添加一个空的TestConfiguration.class )或使用配置文件(例如,“ @ ActiveProfiles(“ integration”))来更改缓存键。

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

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