项目背景:
Maven+TestNG+HTTPClient 的接口测试项目,测试用例主要依赖TestNG的groups来管理和分组
问题描述:
今天照常进行自动化case的维护,添加了一个新的名为CompatibilityScore的类,并在里面加了几个测试用例,这些测试用例都在同一组里
简单代码如下:
public class CompatibilityScore extends TestSuiteSetup {
@BeforeClass(alwaysRun = true)
public void attachTenant() {
//daima
}
@Test(dataProviderClass = DataProviders.class, groups = "api.compatibility.score", dataProvider = "modelIdProvider")
public void bulkScore(String modelId) {
//测试逻辑
}
@Test(dataProviderClass = DataProviders.class, groups = "api.compatibility.score", dataProvider = "modelIdProvider")
public void bulkScoreWithEnrich(String modelId) {
//测试逻辑
}
@Test(dataProviderClass = DataProviders.class, groups = "api.compatibility.score", dataProvider = "modelIdProvider")
public void RTSScore(String modelId) {
//测试逻辑
}
}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value> <!-- disabling default listeners is optional -->
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,
org.uncommons.reportng.JUnitXMLReporter</value>
</property>
<property>
<name>surefire.testng.verbose</name>
<value>1</value>
</property>
<groups>${groups}</groups>
<testFailureIgnore>true</testFailureIgnore>
<parallel>methods</parallel>
<threadCount>3</threadCount>
</configuration>
</plugin>
然后执行 下列命令来执行测试用例
mvn clean test -Dgroups=api.compatibility.score
但是却得到了如下结果
===============================================
Surefire suite
Total tests run: 0, Failures: 0, Skips: 0
===============================================
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 96.453 sec - in TestSuite
竟然没有探测到新的测试用例?!
开启mvn的debug再次执行
mvn -X clean test -Dgroups=api.compatibility.score
看到这么一句
Forking command line: cmd.exe /X /C "C:\Java\jdk1.8.0_112\jre\bin\java -jar PROJECT_PATH\target\sure
fire\surefirebooter4790391759985822523.jar PROJECT_PATH\target\surefire\surefire5239123421203456458tmp PROJECT_PATH\target\surefire\surefire_02709615893746419650tmp"
这就是最终执行的命令,找到对应的路径下用文档编辑工具打开surefire5239123421203456458tmp
以我的为例,里面主要一段是这样的
#surefire
#Tue Jan 17 15:23:03 CST 2017
tc.5=com.lattice.qa.api.model.ModelMigrationTest
tc.6=com.lattice.qa.api.model.PMMLModelCreationTest
tc.3=com.lattice.qa.api.model.DeDupTest
tc.4=com.lattice.qa.api.model.ModelCreationTest
tc.1=com.lattice.qa.api.correctness.MultipleModelsTest
tc.2=com.lattice.qa.api.integration.End2EndTest
tc.0=com.lattice.qa.api.correctness.EventTableValuesTest
listener=org.uncommons.reportng.HTMLReporter,\n\t\t\t\t\t\t\t\torg.uncommons.reportng.JUnitXMLReporter
threadcount=3
tc.9=com.lattice.qa.api.scoring.RealTimeScoringTest
tc.20=com.lattice.qa.unit.MapsTest
tc.7=com.lattice.qa.api.model.RefineNCloneTest
tc.21=com.lattice.qa.unit.MarketoTest
tc.8=com.lattice.qa.api.scoring.BulkScoringTest
tc.22=com.lattice.qa.unit.TenantConsoleTest
tc.12=com.lattice.qa.api.scoring.ScoringBackwardCompatibilityTest
tc.13=com.lattice.qa.CleanupTenantsTest
tc.14=com.lattice.qa.performance.ScoreingPerfTest
tc.15=com.lattice.qa.sample.basic.BasicTest
tc.16=com.lattice.qa.sample.db.ruid.RUIDSampleTest
parallel=methods
tc.17=com.lattice.qa.TestSuiteSetup
tc.18=com.lattice.qa.unit.AvroParserTest
tc.19=com.lattice.qa.unit.LPRestAPI3Test
groups=api.compatibility.scor
surefire.testng.verbose=1
tc.10=com.lattice.qa.api.scoring.RTSBackwardCompatibilityTest
usedefaultlisteners=false
tc.11=com.lattice.qa.api.scoring.RTSTest
tc.23=com.lattice.qa.unit.TenantsCleanTest
这些以tc开头的属性定义就指定了测试用例所在的类但是看了一遍并没有找到我刚才定义的类CompatibilityScore,这也就是为什么maven执行的时候会找不到测试用例.
那么为什么maven 找不到这个类呢....
再次Google发现是因为 surefire plugin 默认只能识别以Test开头或者Test,TestCase结尾的java文件. 真是够奇葩
By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:
- "*/Test.java" - includes all of its subdirectories and all java filenames that start with "Test".
- "**/*Test.java" - includes all of its subdirectories and all java filenames that end with "Test".
- "**/*TestCase.java" - includes all of its subdirectories and all java filenames that end with "TestCase".
再次把文件名改成CompatibilityScoreTest.java 后 顺利执行.
行文寥做备忘.