在构建期间不会运行Spring启动集成测试

时间:2017-04-26 13:42:18

标签: java spring-boot

当我构建项目时(无论是否使用maven of terminal),集成测试都不会运行。 这是日志:

15:10:20.381 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.company.abc.restrictions.AddInterfaceTest]
15:10:20.396 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
15:10:20.412 [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)]
15:10:20.427 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.company.abc.restrictions.AddInterfaceTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
15:10:20.669 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.company.abc.transactions.VisaCreditTest]: using defaults.
15:10:20.684 [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]
15:10:20.684 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@557caf28, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@408d971b, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@6c6cb480, org.springframework.test.context.support.DirtiesContextTestExecutionListener@3c46e67a, org.springframework.test.context.transaction.TransactionalTestExecutionListener@c730b35, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@206a70ef, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@292b08d6, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@22555ebf, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@36ebc363, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@45752059, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@34e9fd99, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@3c41ed1d]
15:10:20.684 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.company.abc.transactions.VisaDebitTest], using SpringBootContextLoader
15:10:20.684 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.company.abc.transactions.VisaDebitTest]: class path resource [com/company/abc/transactions/VisaDebitTest-context.xml] does not exist
15:10:20.684 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.company.abc.transactions.VisaDebitTest]: class path resource [com/company/abc/transactions/VisaDebitTestContext.groovy] does not exist
15:10:20.684 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.company.abc.transactions.VisaDebitTest]: no resource found for suffixes {-context.xml, Context.groovy}.
15:10:20.684 [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.company.abc.transactions.VisaDebitTest]
15:10:20.684 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.company.abc.transactions.VisaDebitTest]: using defaults.
15:10:20.684 [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]
15:10:20.700 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@6ad82709, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@510f3d34, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@7817fd62, org.springframework.test.context.support.DirtiesContextTestExecutionListener@8297b3a, org.springframework.test.context.transaction.TransactionalTestExecutionListener@2362f559, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@b2c9a9c, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@4c178a76, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@fa4c865, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@3bd82cf5, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@544fa968, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@247bddad, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@d35dea7]
15:10:20.700 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.company.abc.restrictions.AddInterfaceTest]
15:10:20.700 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.company.abc.restrictions.AddInterfaceTest]

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

这是主要的测试类:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyServiceStarter.class, webEnvironment= SpringBootTest.WebEnvironment.DEFINED_PORT,
        properties = {"flyway.locations=filesystem:../database/h2", "server.port=9100", "spring.profiles.default=dev"})
@Category(IntegrationTest.class)
public abstract class AbstractModulIntegrationTest { ... }

任何信息表示赞赏。

1 个答案:

答案 0 :(得分:0)

如果你使用spring-boot-parent pom,你可以进入它并查看这些行

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <includes>
                            <include>**/*Tests.java</include>
                            <include>**/*Test.java</include>
                        </includes>
                        <excludes>
                            <exclude>**/Abstract*.java</exclude>
                        </excludes>
                    </configuration>
                </plugin>   

正如您所看到的那样,摘要被排除在外。因此它没有执行。更改测试类的名称或覆盖此插件并删除此行

<exclude>**/Abstract*.java</exclude>