java注释 category_java – 使用SpringRunner.class的JUnit @Category注释

我遵循

this blog post使用@Category注释设置了具有单独的单元和集成测试的Maven构建.

在大多数情况下,这是有效的:标记为@Category(IntegrationTest.class)的测试在集成测试阶段执行,所有未标记的测试在测试阶段执行.

但是,即使测试本身没有运行,看起来在运行单元测试时仍然会(部分?)创建集成测试的上下文:

[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ bamboo ---

[INFO] Surefire report directory: [removed]

[INFO] Using configured provider org.apache.maven.surefire.junitcore.JUnitCoreProvider

[INFO] parallel='none', perCoreThreadCount=true, threadCount=0, useUnlimitedThreads=false, threadCountSuites=0, threadCountClasses=0, threadCountMethods=0, parallelOptimized=true

-------------------------------------------------------

T E S T S

-------------------------------------------------------

09:56:05.458 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.example.MyIntegrationTest]

09:56:05.463 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]

09:56:05.468 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]

09:56:05.481 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.example.MyIntegrationTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]

09:56:05.494 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.example.MyIntegrationTest], using SpringBootContextLoader

09:56:05.497 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.MyIntegrationTest]: class path resource [com/example/MyIntegrationTest-context.xml] does not exist

09:56:05.497 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.MyIntegrationTest]: class path resource [com/example/MyIntegrationTestContext.groovy] does not exist

09:56:05.497 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.example.MyIntegrationTest]: no resource found for suffixes {-context.xml, Context.groovy}.

09:56:05.530 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.example.MyIntegrationTest]

09:56:05.563 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.example.MyIntegrationTest]: using defaults.

09:56:05.567 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]

09:56:05.580 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext]

09:56:05.586 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@62fdb4a6, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@11e21d0e, org.springframework.test.context.support.DirtiesContextTestExecutionListener@1dd02175, org.springframework.test.context.transaction.TransactionalTestExecutionListener@31206beb, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@3e77a1ed, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@3ffcd140, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@23bb8443, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@1176dcec, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@120d6fe6, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@4ba2ca36, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@3444d69d]

09:56:05.591 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.MyIntegrationTest]

09:56:05.591 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.MyIntegrationTest]

Running com.example.MyUnitTest

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.323 sec - in com.example.MyUnitTest

这就是MyIntegrationTest的注释方式:

@Category(IntegrationTest.class)

@RunWith(SpringRunner.class)

@SpringBootTest(classes = TestApp.class)

public class MyIntegrationTest {

@Autowired

private ActualObject actualObject;

}

我该如何防止这种行为?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值