一、工具
1、jdk:jdk1.8.0_121
2、maven:apache-maven-3.3.9
3、IDEA:IntelliJ IDEA 2018.1.5
二、搭建
1、jdk环境下载配置:参考 jdk配置
2、maven配置
①下载后,解压到指定文件夹:参考 建立maven私服
②右键,我的电脑——>属性——>高级系统设置——>环境变量——>系统变量——>新建,变量名MAVEN_HOME和变量值D:\automateTool\maven,确定

③系统变量PATH,修改变量值,增加变量名: %MAVEN_HOME%\bin;(注意以英文;分隔)
④配置一下Maven的本地仓库路径,进入解压Maven的目录,如D:\automateTool\maven\conf,找到settings.xml文件,进行本地仓路径修改,默认即可


3、IDEA设置maven
①File——>Settings...——>Maven,修改相关路径,OK即可

4、创建工程项目
①File——>new ——>Project——>Next——>Next——>finish


②点击test目录新建module,modul下自动生成文件,打开——>src——>pom.xml,添加依赖的jar包

5、TestNG配置
①添加TestNG依赖包
<!--添加testng依赖包-->
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
</dependency>
</dependencies>

②添加编译插件和执行测试插件
<!--添加编译插件和执行测试插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgs>
<arg>-Xlint:unchecked</arg>
<arg>-Xlint:deprecation </arg>
<!--<arg>endorseddirs=${endorsed.dir}</arg>-->
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<file>res/testNG.xml</file>
</suiteXmlFiles>
<!--<workingDirectory>target/</workingDirectory>-->
</configuration>
</plugin>

③创建测试类
public class test {//这个是类
public static void main(String[] args) { //这个是入口函数
System.out.println("asdsa");
}
@Test//因为这里声明了Test,所以效果和public static void main(String[] args) 一样,其实是简写了
public void testcase1(){//这个是测试的入口
Assert.assertTrue(false);
System.out.println("testcase1");
}
@Test//因为这里声明了Test,所以效果和public static void main(String[] args) 一样,其实是简写了
public void testcase2(){//这个东西叫函数,也叫方法
Assert.assertTrue(true);
System.out.println("testcase1");
}
}

网友评论