win10搭建testNG测试环境详解

该博客介绍了在IntelliJ IDEA中搭建并运行TestNG项目的详细步骤。包括安装JDK、IntelliJ IDEA,创建工程,安装TestNG及相关插件,创建Java类,配置pom.xml和testng.xml文件,最后运行测试类,还提到配置依赖时选用户数多的版本。

一、安装jdk-8u191-windows-x64.exe

新建系统环境变量JAVA_HOME并配置Java搜索路径位置

 二、安装IntelliJ IDEA

三、用New Project按钮创建工程(TestNG_Example)     

四、安装TestNG和Create TestNG XML插件

五、如图创建一个Java类HelloWorld

import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

public class HelloWorld {

    @BeforeClass
    public void Initiate() {
        System.out.println("This is before class");
    }

    @AfterClass
    public void FinalClose() {
        System.out.println("This is after class");
    }

    @Test
    public void Function1() {
        System.out.println("This is TestNG test case1");
    }

    @Test
    public void Function2() {
        System.out.println("This is TestNG test case2");
    }

    @Test
    public void Function3() {
        System.out.println("This is TestNG test case3");
    }
}

 六、pom.xml文件配置如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>TestNG_Example</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

七、Create TestNG XML

八、全选用Ctrl+Alt+L格式化testng.xml

九、在testng.xml文件添加类HelloWorld

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite">
    <test verbose="2" preserve-order="true" name="C:/project/TestNG_Example/src/test/java">
        <classes>
            <class name="HelloWorld"></class>
        </classes>
    </test>
</suite>

十、运行HelloWorld测试类

十一、在pom.xml中配置安装依赖testng时版本选用户数多的

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

princewwj

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值