在同一个包下新建CalculateTest类,然后便可在idea中运行
package com.coke.util;
import org.junit.*;
public class CalculateTest {
@Test
public void testAdd(){
int result = new Calculate().add(1,2);
Assert.assertEquals(3,result);
}
@Test
public void testSub(){int result = new Calculate().sub(4,1);
Assert.assertEquals(3,result);
System.out.println('123');
}
@Test
public void testDiv(){
int result = new Calculate().p(8,2);
Assert.assertEquals(4,result);
}
}
junit执行测试用例
post方法请求接口并获取返回response对象
import static io.restassured.RestAssured.given;
import io.restassured.response.Response;
public class RestDemo {
@Test
public void testGetHtml(){
Response response =
given().
log().all().
body().
param('wd', '豆瓣').
when().
post('http://www.baidu.com/').
then().
log().all().
statusCode(200).
extract().
response();
}
given():一次网络请求所需要的条件都写在这里,头信息、query参数
when():触发条件
then():断言
extract():提取返回值
get方法请求接口并获取返回response对象
import static io.restassured.RestAssured.given;
import io.restassured.response.Response;
public class RestDemo {
@Test
public void testGetHtml(){
Response response =
given().
log().all().
param('wd', '豆瓣').
when().
get('http://www.baidu.com/').
then().
log().all().
statusCode(200).
extract().
response();
}
given():一次网络请求所需要的条件都写在这里,头信息、query参数
when():触发条件
then():断言
extract():提取返回值
文章为作者独立观点,不代表股票交易接口观点