怎么用命令行执行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>

就这样解决了我的问题了 ,开森

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值