import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import autoWebApiRequest.HttpRequest;
public class UnsubscribesTestCaseTNG {
String testString ;
String add_unsubscribes ;
@BeforeClass
public void setUp() throws Exception {
this.testString = "https://xxx.xxxx";
this.add_unsubscribes = this.testString +
"xxx.xxxx";
}
public static void testAssert(String tString, String resultString){
String eString;
try {
eString = HttpRequest.webApiResult(tString);
assertThat(eString, containsString(resultString));
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Test
@Parameters({"resultString","userName","pwd","email"})
public void add_unsubscribes(String resultString,String userName, String pwd,String email) {
String tString = add_unsubscribes + "api_user="+userName+"&api_key="+pwd+"&email="+email;
System.out.println(tString);
testAssert(tString, resultString);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
public class HttpRequest {
//发送一般Get请求
public static String webApiResult(String url) throws ClientProtocolException, IOException{
String str = null;
HttpClient httpclient = new DefaultHttpClient();
// 创建Get方法实例
HttpGet httpgets = new HttpGet(url);
HttpResponse response = httpclient.execute(httpgets);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instreams = entity.getContent();
str = convertStreamToString(instreams);
httpgets.abort();
}
return str;
}
}
使用testNG完成一般httpclient发送请求的测试
1 定义request发送方法
2 定义testNG发送数据
3 获取response消息,并对比结果
分享到:
相关推荐
java+selenium+maven+testng自动化测试框架实例(实际项目)
ant+eclipse+testng实例代码。包含了配置testng.xml和ant的build.xml文件。导入到eclipse中可以直接运行。前提是eclipse中已经安装了testng插件和ant插件。相关的jar包需要引用进来。
本文内容包括:关于代码TestNG快速起步定义测试组配置方法异常检测结束语JUnit框架是Java语言单元测试当前的一站式解决方案。这个框架值得称赞,因为它把测试驱动的开发思想介绍给Java开发人员并教给他们如何有效地...
TestNG中文手册及学习笔记,包括:环境配置、详细使用说明及实例。
学习笔记资料来源:http://www.yiibai.com/testng/;从易佰TestNG教程整理,包括概念介绍,代码实例。
testng介绍、实例、教程
主要对举例对国家气象局接口自动化测试进行讲解(Get请求及结果断言),以达到自动化测试入门目的,需要有一定的JAVA知识(HTTP相关)。
终极自动化测试环境搭建:Selenium+Eclipse+Junit+TestNG+Python。 使用最新版本软件,所有步骤均有截图,5个代码实例。
本文介绍和对比了TestNG和junit框架,并举出实例说明。 同时讲解了Mockito和Dbunit框架的使用
使用TestNG-Abbot实现自动化GUI测试[3]软件测试在清单1中,我创建了一个TestNG测试(实际上并没有对其做任何测试),该测试在fixture中使用TestNG-Abbot的AbbotFixture对象来存放WordFinderGUI的实例。清单1.使用Abbo...
删除典型的样板文件,例如在测试失败时截取屏幕截图、配置 WebDriver 和实例化页面对象。 使用 PageFactory 定义页面对象的声明方式。 单独配置测试的声明方式。Maven 依赖您可以将TestNG-Selenium添加到现有项目中...
主要介绍了java 与testng利用XML做数据源的数据驱动示例详解的相关资料,需要的朋友可以参考下
新手学习jsp的精品教材,jstl的经典实例,大家欢迎学习和下载
Selenide-TestNG-Allure2-框架 适用于java,selenide和testng的测试自动化框架。 完全托管的驱动程序实例,分发,并行化(以及更多!)。 快速运行并快速进行书写测试,而无需构建不必要的样板
需要Eclipse的TestNG插件 运行'./gradlew eclipse'以下载依赖项 作为TestNG项目运行threadLocalDemo.xml 设置runLocal = true或false以创建WebDriver或RemoteWebDriver实例
#Allure TestNG 重试监听器 ITestListener 的实现以允许“重试功能”以结合框架和框架。 请参阅此处的 JavaDocs (TBD)。 ##特征: 如果测试已重试,则其结果状态将从“失败”(“已损坏”)更改为“待定”,并...
QuickCheckNG是Java注释处理器,用于为一组QuickCheck生成器生成TestNG @DataProvider方法。 建造 mvn clean install 用法 在您的项目中包含一个名为*Generators.java的类,该类具有一组返回Generator实例的public ...
使用反射方式构造对象实例 第 7 章 在测试代码中使用Mock 静态mock,new MockUp的使用 mock构造函数和静态代码块 new MockUp和spring的集成 针对静态mock做断言 动态mock,new Expectations的使用
使用 Atlassian 的公共实例“A Test Project”进行测试TestNG 成功报告和日志在 C:\Users\sowbaranip\Desktop\Final\JIRA_AutomationTest\test-output 下可用测试运行执行视频分享于 JIRA 自动化测试