目录
1.2 在Eclipse中单击“Window>Proferences>Maven>User Settings>Browse”,选择“C:\Users\jss\.m2\setting.xml”文件
4.1 在建好的Maven工程中,新建TestNG class
前言
最近做软件测试实习生,在学校里没有学习过,买了些资料,一边学一边分享,如果有错请指正,欢迎在评论区讨论。
准备工作
安装好Eclipse
一、配置Maven
1.1 settings.xml文件
在C:\Users\jss\.m2目录中新增setting.xml文件,可以先新建一个文本文档,修改后缀名实现;若不存在该目录自行创建即可;其中jss需要替换成你们自己的用户名。
在该文档中输入以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>JDK-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
</settings>
这段代码是经过删改后的,如果想查看源代码,可以移步https://blog.csdn.net/huo920/article/details/82082403查看源码
其中<mirror>标签将Maven中央仓库下载依赖文件配置到了国内的阿里云,提高下载的速度。
1.2 在Eclipse中单击“Window>Proferences>Maven>User Settings>Browse”,选择“C:\Users\jss\.m2\setting.xml”文件
依次点击Update Setting、Apply and Close,完成Maven配置
二、创建Maven工程
在Eclipse新建工程界面选择Maven工程
勾选创建简单工程,不使用模板;
输入工程名和项目名:
其中Group Id代表组织唯一标识符,Artifact Id代表该组织内唯一标识符。G id类比为公司的话,A id就是其中一个项目。Name为项目完整名字,点击Finish完成工程创建,出现名叫test2的工程。
三、安装TestNG
3.1配置TestNG依赖
以前可以通过在pom.xml文件中写代码下载TestNG,代码我懒得敲直接给网盘链接:
链接: https://pan.baidu.com/s/1s87r1lncuTpXvlMtOUKzSQ 提取码: ucqt
3.2安装TestNG插件
将下载好的文件解压到能找到的路径下,在Eclipse中单击“Help>Install New Software”
按如图顺序找到文件夹,点击确认、OK后显示TestNG插件,勾选后进行安装,安装完成后会重启Eclipse。
四、验证安装
4.1 在建好的Maven工程中,新建TestNG class
选中other
找到TestNG Class,点击next
输入包名
点击Finish完成创建。
4.2 添加TestNG库
右键工程文件夹,找到add libraries
添加TestNG库
在新建的TestNG class中输入以下代码
package jss.test2;
import org.testng.annotations.Test;
public class NewTest {
@Test
public void f() {
System.out.println("hello");
}
}
点击运行。在下方出现测试报告即配置成功。