我有一个maven项目(appium/java),它是用Intellij编写的。要运行测试,我必须运行testng.xml文件。我想从命令行运行我的测试脚本。我怎么能这么做?我已经找到了从命令行运行testng.xml的各种链接,但是没有一个解决方案适合我。提前感谢
发布于 2019-01-02 10:51:26
由于您的maven项目,您可以在导航到您的项目路径后从命令行使用选项mvn干净测试。这将在testng.xml文件中运行测试。
如果您有多个测试xml文件,则可以使用万岁插件。在您的pom.xml中需要添加如下内容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFiles}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>添加所需的多个suiteXmlFile标记&它应该指向test1.xml、test2.xml等的位置,然后在命令行中使用以下命令
mvn clean test -DsuiteXmlFile.suiteXmlFiles=path/to/test1.xml如果要运行多个测试xml文件,可以使用以下命令
mvn clean test -DsuiteXmlFile.suiteXmlFiles=path/to/test1.xml,path/to/test2.xml希望这能有所帮助
发布于 2019-01-07 03:44:35
如果您正在使用testng.xml文件运行appium案例,那么您可以使用maven的尽力而为的插件来使用maven运行testng文件。maven,您可以使用命令行运行。
因此,基本上您可以运行maven命令,它将在内部使用尽力而为的插件运行您的tesng.xml文件。在构建部分中的pom文件中添加这样的插件,如下所示。然后运行mvn测试命令,它将工作。
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>Give your testng.xml file path</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>https://stackoverflow.com/questions/54004797
复制相似问题