当前位置: 移动技术网 > IT编程>开发语言>Java > (Mac) IDEA上搭建TestNG框架 01

(Mac) IDEA上搭建TestNG框架 01

2020年07月03日  | 移动技术网IT编程  | 我要评论

环境:IDEA + TestNG + Maven

1、创建一个 Maven 项目

https://blog.csdn.net/weixin_39209728/article/details/85853516

File > New > Maven

创建后项目目录:

 

2、pom.xml 配置--带入依赖包

1)百度搜索:maven responsitory

 网址: https://mvnrepository.com/

2)搜索:selenium、testng、、、、

选择使用人数多的版本进入,复制相应内容到pom.xml中。

 

3) 在pom文件中关联配置 maven & testng

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <verbose>true</verbose>
                    <!--在新的虚拟机中开启-->
                    <fork>true</fork>
                    <compilerVersion>1.8</compilerVersion>
                    <encoding>utf-8</encoding>
                    <!--源代码的编译-->
                    <source>1.8</source>
                    <target>1.8</target>

                </configuration>

                </plugin>
                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <suiteXmlFiles>
                        <!--可以添加多个xml文件-->
                        <file>testng.xml</file>
                    </suiteXmlFiles>

                    <properties>
                        <property>

                            <!--日志级别,0-10,10最详细-->
                            <name>surefire.testng.verbose</name>
                            <value>5</value>
                            <!--允许并行-->
                            <name>suitethreadpoolsize</name>
                            <value>2</value>
                            
                        </property>
                    </properties>
                </configuration>
            </plugin>
        </plugins>
    </build>

4) 安装 Create TestNG XML 和lombok插件

  • Mac:IntelliJ IDEA -> Preferences -> Plugins;
  • Windows:File -> Settings -> Plugins.

 

 

安装成功后,右键项目-Create TestNG XML

6)编写testNG.xml

3、创建测试类

 

代码如下:

package com.zytest;

import org.testng.Assert;

import org.testng.annotations.Test;

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

4、编写TestNG.xml

创建 resources 文件,在里面可以创建 testNG.xml (可自定义,需要在pom.xnl修改相应文件名)

 

至此,初度搭建完成,后续还有一些配置

运行结果如下图

 

本文地址:https://blog.csdn.net/xueningyang555/article/details/88827189

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网