欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

(Mac) IDEA上搭建TestNG框架

程序员文章站 2023-11-05 11:08:58
环境:IDEA + TestNG + Maven1、创建一个 Maven 项目File > New > Maven创建后项目目录:2、pom.xml 配置--带入依赖包1)百度搜索:maven responsitory2)搜索:selenium、testng、、、、选择使用人数多的版本进入,复制相应内容到pom.xml中。3......

环境:IDEA + TestNG + Maven

1、创建一个 Maven 项目

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

(Mac) IDEA上搭建TestNG框架

File > New > Maven

(Mac) IDEA上搭建TestNG框架

(Mac) IDEA上搭建TestNG框架

创建后项目目录:

 

(Mac) IDEA上搭建TestNG框架

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

1)百度搜索:maven responsitory

 网址: https://mvnrepository.com/

(Mac) IDEA上搭建TestNG框架

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

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

 

(Mac) IDEA上搭建TestNG框架

(Mac) IDEA上搭建TestNG框架

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.

(Mac) IDEA上搭建TestNG框架

 

(Mac) IDEA上搭建TestNG框架

 

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

(Mac) IDEA上搭建TestNG框架

6)编写testNG.xml

3、创建测试类

(Mac) IDEA上搭建TestNG框架

 

代码如下:

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修改相应文件名)

(Mac) IDEA上搭建TestNG框架

 

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

运行结果如下图

(Mac) IDEA上搭建TestNG框架

 

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