Maven+IDEA+testNG测试框架学习

原文:

https://www.jianshu.com/p/f76d04de982b

https://blog.csdn.net/langsand/article/details/53764805

一、所需环境

1、JDK

2、Maven

3、intellij idea

二、创建工程

Create New Project-Maven-Next-Finish

完成之后的工程目录

三、导入相关依赖包和插件

1)导入testNG依赖包

在pom.xml中添加

    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.21</version>
        </dependency>
    </dependencies>

2)添加编译插件和执行测试插件

在pom.xml中添加

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.15</version>
                <configuration>
                    <!--<testFailureIgnore>true</testFailureIgnore>-->
                    <forkMode>never</forkMode>
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                    <suiteXmlFiles>
                        <suiteXmlFile>xml/testNG.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>

四、创建测试类

(1)在Java文件夹下创建

输入代码:

import org.testng.Assert;
import org.testng.annotations.Test;

public class TestDemo {
    @Test
    public void testcase1(){
        Assert.assertTrue(false);
        System.out.println("testcase1");
    }
}

(2)编写testNG.xml

xml文件用于按照需要批量执行用例,右键选择运行可独立执行

<?xml version="1.0" encoding="utf-8" ?>
<suite name="testproj" parallel="false">
    <test name="testDemo1">
        <classes>
            <class name="TestDemo"></class>
        </classes>
    </test>
</suite>

猜你喜欢

转载自www.cnblogs.com/yinqanne/p/9318736.html
今日推荐