zoukankan      html  css  js  c++  java
  • Jmter 中的JUnit Request

    jmter JUnit Request的入门使用:

      配置好java的环境后,打开eclipse,新建java project,引入相关jar,编写代码调试通过后,导出jar,放到jmeter目录下的lib路径后重启jmeter;

     1 package com.test.junit;
     2 
     3 import static junit.framework.Assert.assertTrue;
     4 import java.util.ArrayList;
     5 import java.util.List;
     6 
     7 import com.alibaba.fastjson.JSON;
     8 import com.alibaba.fastjson.JSONArray;
     9 import com.alibaba.fastjson.JSONObject;
    10 
    11 import org.junit.After;
    12 import org.junit.Before;
    13 import org.junit.Test;
    14 
    15 public class JmeterJunit1 {
    16 
    17     public static String response_data = "{data:{pageNo:[1,2],list:[{id:2,name:\"admin\"},{id:3,name:\"person\"}]}}";
    18     public static List list = new ArrayList();
    19 
    20     @Before
    21     public void setUp() throws Exception {
    22 
    23         JSONObject data_obj = JSON.parseObject(response_data);
    24         String json = data_obj.get("data").toString();
    25         JSONObject jso = JSON.parseObject(json);// json字符串转换成jsonobject对象
    26         
    27         JSONArray jsarr = jso.getJSONArray("list");// jsonobject对象取得list对应的jsonarray数组
    28         
    29         
    30         for (int i = 0; i < jsarr.size(); i++) {
    31             JSONObject ao = jsarr.getJSONObject(i);// jsonarray对象通过getjsonobjext(index)方法取得数组里面的jsonobject对象
    32 
    33             String vString = ao.getString("name");// jsonobject对象通过key直接取得String的值
    34             if (vString == null) {
    35                 vString = ao.getString("username");
    36             }
    37             
    38             list.add(vString);
    39             
    40         }
    41         System.out.println("list---" + list + "\n");
    42     }
    43 
    44     @After
    45     public void tearDown() throws Exception {
    46 
    47     }
    48 
    49     public void check(String name) {
    50         boolean actualResult = list.contains(name);
    51         assertTrue("the expected status is " + name + ", but now it's not", actualResult);
    52     }
    53 
    54     @Test
    55     public void test1() throws Exception {
    56         check("admin");
    57     }
    58 
    59     @Test
    60     public void test2() throws Exception {
    61         check("person");
    62     }
    63 
    64     @Test
    65     public void test3() throws Exception {
    66         check("admin22");
    67     }
    68 
    69 }
    View Code

      

    jmeter 新建junit request

     

    填写项目包的名字,即可选择类,类中声明多少测试方法即可选择多个方法进行测试

    @成为那个自己
  • 相关阅读:
    C++模板&泛型编程
    C++继承
    测试pc大、小端
    C语言标准定义的32个关键字
    *塔,菱形
    练习小题目
    c一些关键字
    uvaoj 489
    uvaoj1339
    hdu1969Pie(根据体积二分,分馅饼)
  • 原文地址:https://www.cnblogs.com/xiaochou1024/p/9443272.html
Copyright © 2011-2022 走看看