gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:31:23 25 4
gpt4 key购买 nike

我正在 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 进行多次测试运行”的搜索都解释了如何有意地进行。

最佳答案

你的测试类中有没有匿名内部类?就是这样MultiChannelContentServiceIntegrationTest$22 等似乎表明。

显然,模式

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

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

试试 **/*Test.java 或简单地使用默认值。

关于maven - 为什么 TestNG 会多次运行这些测试类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20815922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com