Maven testng集成 - 在maven测试阶段,testng.xml外部的测试正在运行

时间:2016-03-11 16:12:11

标签: maven testng maven-surefire-plugin

我正在尝试仅运行testng.xml中存在的测试方法。 Maven目标 -

test -Ptest1 -DargLine="-Dbrowser=firefox" -Dmaven.test.failure.ignore=true

当我尝试执行上述目标时,testng.xml之外的测试也会被执行。(测试以* Test开头/结尾)

<profile>
        <id>test1</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.1</version>
                    <executions>
                        <execution>
                            <phase>compile</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <echo>Using env.test1.properties</echo>
                                    <copy file="src/test/resources/env.test1.properties"
                                        tofile="src/test/resources/env.properties" overwrite="true" />
                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-report-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <suiteXmlFiles>
                            <file>src/test/resources/testng.xml</file>
                        </suiteXmlFiles>
                        <systemPropertyVariables>
                            <propertyName>browser</propertyName>
                            <buildDirectory>${project.build.directory}</buildDirectory>
                        </systemPropertyVariables>

                    </configuration>
                    <!-- <executions>
                        <execution>
                            <phase>compile</phase>
                            <goals>
                                <goal>java</goal>
                            </goals>
                        </execution>
                    </executions> -->
                </plugin>
            </plugins>
        </build>
    </profile>

我的testng.xml文件看起来像这样

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Maven tutorial" verbose="3" >
<test name="Testie">
    <!-- <parameter name="browser" value="firefox"></parameter> -->
    <classes>
        <class name="com.maven.tutorial.hello2Test"></class>

    </classes>
</test>

<test name="Testff">
    <!-- <parameter name="browser" value="firefox"></parameter> -->
    <classes>

        <class name="com.maven.tutorial.hello4Test"></class>
    </classes>
</test>
</suite>

当我运行maven目标时,它会执行hello2Test类中的测试,hello4Test以及以Test结尾的其他类。

2 个答案:

答案 0 :(得分:0)

更改

 <suiteXmlFiles>
    <file>src/test/resources/testng.xml</file>
 </suiteXmlFiles>

 <suiteXmlFiles>
    <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
 </suiteXmlFiles>

答案 1 :(得分:0)

我必须从

更改我的插件
 <artifactId>maven-surefire-report-plugin</artifactId>

 <artifactId>maven-surefire-plugin</artifactId>