怎么用命令行执行testng.xml,解决办法
这段时间自己在搭建一个接口测试框架,其中使用到了testng,接口都写完了也调试完成准备集成到Jenkins,需要使用命令来调代码中的testng.xml ,查testng官网说是用
java org.testng.TestNG testng1.xml 就可以了,结果我试了无数次都不行,难受。。。
后来我看有朋友发帖说这样子可以
我试了一下 还是不行,你们也可以试试,或许可以
直接说一下我的解决办法吧
我是用maven起的指定特定的testng.xml
命令如下:
mvn clean test -Dsurefire.suiteXmlFiles=src/main/resources/testng_user.xml
注意要在你的项目路径下执行
依赖的maven项目
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.allinmd.Starter</mainClass> </configuration> </plugin> <!-- 指定jdk --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> <source>1.8</source> <target>1.8</target> </configuration> <version>3.5.1</version> </plugin> <!--maven-surefire-plugin的test目标会自动执行测试源码路径(默认为src/test/java/)下所有符合一组命名模式的测试类--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> <argLine> -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" </argLine> <!-- <skipTests>true</skipTests>--> </configuration> <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectj.version}</version> </dependency> </dependencies> </plugin> <plugin> <groupId>com.lewisd</groupId> <artifactId>lint-maven-plugin</artifactId> <version>0.0.8</version> <executions> <execution> <id>pom-lint</id> <phase>validate</phase> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>com.lewisd</groupId> <artifactId>lint-maven-plugin</artifactId> <version>0.0.8</version> <configuration> <failOnViolation>false</failOnViolation> <onlyRunRules> <rule>ExecutionId</rule> </onlyRunRules> <xmlOutputFile>${project.build.directory}/maven-lint-result.xml</xmlOutputFile> </configuration> <executions> <execution> <id>pom-lint</id> <phase>validate</phase> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
就这样解决了我的问题了 ,开森