TestNG+Maven+IDEA 自动化测试(二) TestNG.xml

maven插件引入

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArgs>
                        <arg>-Xlint:unchecked</arg>
                        <arg>-Xlint:deprecation </arg>
                        <!--<arg>endorseddirs=${endorsed.dir}</arg>-->
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <suiteXmlFiles>
                        <file>res/testNG.xml</file>
                    </suiteXmlFiles>
                    <!--<workingDirectory>target/</workingDirectory>-->
                </configuration>
            </plugin>
        </plugins>
    </build>

在项目下新建 res目录,然后在res目录下新建 testNG.xml 文件

文件内容如下:

<?xml version="1.0" encoding="utf-8" ?>
<suite name="testproj">
    <test name="testDemo1">
        <groups>
            <run>
                <include name="fast" />
                <include name="slow" />
            </run>
        </groups>
        <classes>
            <class name="com.ryan.HelloTestNG"></class>
        </classes>
    </test>
</suite>

直接用xml文件运行

右键点击testNG.xml 点击run,如下图所示:

mvn 命令

mvn clean test

猜你喜欢

转载自www.cnblogs.com/ryan255/p/9388191.html