一开始雄心壮志想二次开发开源的接口测试平台为我们所用,后来在遇到各种报错中手足无措,寸步难行~~
一句总结我这一小个星期:接口测试平台:从开始到放弃
现在老老实实先自己用代码写写脚本,从瘦子变胖子吧,嗯~身材上我已经实现了,明年的愿望就是瘦10斤,女人,就是要作!!!
这次是准备用java+testng+idea写接口测试,之前是用的postman工具做的自动化,思来想去,虽然我代码上是个白痴,但也不能不学,毕竟大势所趋,只能向金钱低头,能学习到多少便学多少吧!
首先,默认你已经下载了idea,破解了,并且安装了jdk,配置好了环境变量,然后下载好了maven,不懂百度
然后新建一个maven项目,在pom文件里下载依赖或者手动去下,我选第一个
<?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>evanui</groupId>
<artifactId>evanui</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.54</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.1</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<!--<testFailureIgnore>true</testFailureIgnore>-->
<forkMode>never</forkMode>
<argLine>-Dfile.encoding=UTF-8</argLine>
<suiteXmlFiles>
<suiteXmlFile>xml/testNG.xml</suiteXmlFile>
<suite name="evanui" parallel="false">
<test name="testcase1">
<classes>
<class name="xzt.Test1"></class>
</classes>
</test>
</suite>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
如果反复下载不了,确认下名字是否拼写正确,并且版本是否正确 ,可以去这个网站查看最新的依赖版本--https://mvnrepository.com/
然后,学习使用testng的关键词,嗯,我先抄下来了,后面接口脚本写好了再贴上来哈
@BeforeSuite: The annotated method will be run before all tests in this suite have run. to the classes inside the <test> tag is run. to the classes inside the <test> tag have run. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked. the current class is invoked. current class have been run. |
中文版的
注解 | 描述 |
@BeforeSuite | 注解的方法将只运行一次,运行所有测试前此套件中。 |
@AfterSuite | 注解的方法将只运行一次此套件中的所有测试都运行之后。 |
@BeforeClass | 注解的方法将只运行一次先行先试在当前类中的方法调用。 |
@AfterClass | 注解的方法将只运行一次后已经运行在当前类中的所有测试方法。 |
@BeforeTest | 注解的方法将被运行之前的任何测试方法属于内部类的 <test>标签的运行。 |
@AfterTest | 注解的方法将被运行后,所有的测试方法,属于内部类的<test>标签的运行。 |
@BeforeGroups |
按组( @Test(groups= "findyou") )运行时,此注解在组(findyou组)执行之前运行,可做组(findyou组)执行之前,初始化数据准备类工作。
|
@AfterGroups |
按组( @Test(groups= "findyou") )运行时,此注解在组(findyou组)执行之后运行,可做组(findyou)执行之后,数据还原类工作。
|
@BeforeMethod | 注解的方法将每个测试方法之前运行。 |
@AfterMethod | 被注释的方法将被运行后,每个测试方法。 |
@DataProvider | 标志着一个方法,提供数据的一个测试方法。注解的方法必须返回一个Object[] [],其中每个对象[]的测试方法的参数列表中可以分配。 该@Test 方法,希望从这个DataProvider的接收数据,需要使用一个dataProvider名称等于这个注解的名字。 |
@Factory | 作为一个工厂,返回TestNG的测试类的对象将被用于标记的方法。该方法必须返回Object[]。 |
@Listeners | 定义一个测试类的监听器。 |
@Parameters | 介绍如何将参数传递给@Test方法。 |
@Test | 标记一个类或方法作为测试的一部分。 |