为什么TestNG会多次运行这些测试类?

时间:2013-12-28 14:58:18

标签: maven testing testng

我正在CI服务器(Bamboo)上运行构建和测试。我正在使用TestNG来运行我的集成测试。

当我运行构建和测试(使用Maven)时,我在日志中看到以下内容(这是一个示例,还有其他类也受到影响)

build   27-Dec-2013 19:06:35    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$18
build   27-Dec-2013 19:06:36    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:06:36    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.194 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$18
build   27-Dec-2013 19:06:36    Running c.v.p.i.c.ExerciseLifecycleForStaticAssetIntegrationTest$1
build   27-Dec-2013 19:06:36    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:06:36    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.188 sec - in c.v.p.i.c.ExerciseLifecycleForStaticAssetIntegrationTest$1
build   27-Dec-2013 19:06:36    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$25
build   27-Dec-2013 19:06:36    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:06:36    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.188 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$25
build   27-Dec-2013 19:06:37    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest
build   27-Dec-2013 19:06:37    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:07:57    Tests run: 21, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 80.748 sec <<< FAILURE! - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest
build   27-Dec-2013 19:07:57    testGetPostDescriptorForVersion(c.v.p.i.c.MultiChannelContentServiceIntegrationTest)  Time elapsed: 0.066 sec  <<< FAILURE!
build   27-Dec-2013 19:07:57    java.lang.AssertionError: expected:<1.0> but was:<null>
build   27-Dec-2013 19:07:57        at org.testng.AssertJUnit.assertEquals(AssertJUnit.java:101)
build   27-Dec-2013 19:07:57        at org.testng.AssertJUnit.assertEquals(AssertJUnit.java:108)
build   27-Dec-2013 19:07:57        at c.v.p.i.c.MultiChannelContentServiceIntegrationTest.checkFieldsThatShouldBeTheSameForAllVersions(MultiChannelContentServiceIntegrationTest.java:891)
build   27-Dec-2013 19:07:57        at c.v.p.i.c.MultiChannelContentServiceIntegrationTest.testGetPostDescriptorForVersion(MultiChannelContentServiceIntegrationTest.java:832)
build   27-Dec-2013 19:07:57    
build   27-Dec-2013 19:07:58    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$24
build   27-Dec-2013 19:07:58    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:07:58    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.186 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$24
build   27-Dec-2013 19:07:58    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$15
build   27-Dec-2013 19:07:58    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:07:58    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.183 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$15
build   27-Dec-2013 19:07:58    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$11
build   27-Dec-2013 19:07:59    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:07:59    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.2 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$11
build   27-Dec-2013 19:07:59    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$2
build   27-Dec-2013 19:07:59    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:07:59    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.206 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$2
build   27-Dec-2013 19:07:59    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$22
build   27-Dec-2013 19:07:59    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:08:00    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.189 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$22
build   27-Dec-2013 19:08:00    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$7
build   27-Dec-2013 19:08:00    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:08:00    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.19 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$7
build   27-Dec-2013 19:08:00    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$13
build   27-Dec-2013 19:08:00    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:08:00    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.199 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$13
build   27-Dec-2013 19:08:00    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$16
build   27-Dec-2013 19:08:01    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:08:01    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.214 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$16
build   27-Dec-2013 19:08:01    Running c.v.p.i.c.ExerciseLifecycleIntegrationTestTemplate
build   27-Dec-2013 19:08:01    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:08:01    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.229 sec - in c.v.p.i.c.ExerciseLifecycleIntegrationTestTemplate
build   27-Dec-2013 19:08:01    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$14
build   27-Dec-2013 19:08:01    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:08:02    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.184 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$14
build   27-Dec-2013 19:08:02    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$28
build   27-Dec-2013 19:08:02    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:08:02    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.186 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$28
build   27-Dec-2013 19:08:02    Running c.v.p.i.c.MultiChannelContentServiceIntegrationTest$5
build   27-Dec-2013 19:08:02    Configuring TestNG with: TestNGMapConfigurator
build   27-Dec-2013 19:08:02    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.191 sec - in c.v.p.i.c.MultiChannelContentServiceIntegrationTest$5

我感到困惑的是c.v.p.i.c.MultiChannelContentServiceIntegrationTest$XX的实例。

我没有故意或明确地要求多次运行这些类,也没有多次运行它们(因为它们报告Test runs: 0除了单个实例以外的所有类)。

<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.16</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-testng</artifactId>
            <version>2.16</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>integration-test</id>
            <goals>
                <goal>integration-test</goal>
            </goals>
            <configuration>
                <argLine>
                    -javaagent:"${user.home}/.m2/repository/org/springframework/spring-instrument/${org.springframework.version}/spring-instrument-${org.springframework.version}.jar"
                    -Djava.awt.headless=true -Dehcache.rest.port=9888
                </argLine>
                <includes>
                    <include>c/v/p/integration/**/*.java</include>
                </includes>
                <reuseForks>false</reuseForks>
                <forkCount>1</forkCount>
                <argLine>-Xms512m -Xmx3096m -XX:PermSize=384m -XX:MaxPermSize=512m</argLine>
            </configuration>
        </execution>
    </executions>
</plugin>

有人能指出我可能会发生的事情吗?这种现象并不适合谷歌搜索。大多数“使用TestNG进行多次测试运行”的搜索都解释了如何故意这样做。

1 个答案:

答案 0 :(得分:1)

您的测试类中是否有任何匿名内部类?那是什么 MultiChannelContentServiceIntegrationTest$22等似乎表明了这一点。

显然,模式

<include>c/v/p/integration/**/*.java</include>

包含这些匿名类,因此Surefire尝试将它们作为测试类运行。

尝试**/*Test.java或只使用默认值。