我正在尝试使用Dtest标志从命令行运行单个(或简短的测试列表),例如:
"C:\Program Files (x86)\Jenkins\tools\hudson.tasks.Maven_MavenInstallation\Installed_Automatically\bin\mvn" -B -T 10 -fn -f "C:\Program Files (x86)\Jenkins\workspace\Nightly\qaauto\pom.xml" clean test -PNightly1 -Dtest=testcases.TestCaseA
但是当我拨打电话时,出现错误消息:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project Automation: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
如果我在不使用'-Dtest = testcases.TestCaseA'的情况下运行命令行,它将运行'Nightly1'配置文件中定义的所有测试,包括'TestCaseA'。
我不确定这是否是由于我们的目录绝对不是标准的-例如我们的测试源不在'src / test / java'中,而是在'src / testcases'中,但是我对于为什么没有-Dtest标志就可以正常工作感到困惑。
以下是我们的TestNG配置“ Nightly1”中的示例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Nightly1" parallel="tests" thread-count="10" preserve-order="false">
<parameter name="sauceOs" value="win7" />
<parameter name="browser" value="chrome" />
<parameter name="sauceBrowserVersion" value=""/>
<parameter name="remoteOrLocal" value="remote" />
<parameter name="maxDurationForSauce" value="10800"></parameter>
<parameter name="environment" value="stage" />
<parameter name="remoteAddress" value="1.1.1.1" />
<parameter name="throttle" value="250" />
<listeners>
<listener class-name="utilities.RetryListener"/>
<!--<listener class-name = "utilities.CaptureScreenshot" />-->
</listeners>
<test name="TestCase">
<groups>
<run>
<include name="TestCase"></include>
<exclude name="stupidLong"></exclude>
</run>
</groups>
<packages>
<package name="testcases"/>
</packages>
</test>
</suite>
还有我们的POM示例:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Automation</groupId>
<artifactId>Automation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Automation</name>
<properties>
<!--<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> -->
<maven.compiler.version>3.7.0</maven.compiler.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.surefire.plugin.version>3.0.0-M3</maven.surefire.plugin.version>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
<profiles>
....
<profile>
<id>Nightly1</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<argLine>-Xms1g</argLine>
<argLine>-Xmx2g</argLine>
<argLine>-XX:+HeapDumpOnOutOfMemoryError</argLine>
<argLine>-XX:HeapDumpPath="C:\Program Files (x86)\Jenkins\JavaHeapdumps"</argLine>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>Nightly1.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
...