jmeter create an interface test cases

1 how do interface testing?

  In general, the front and rear we call the project is mainly based on the http protocol interfaces, it is mainly through the tool or code to simulate http request to send and receive test interface. Below we compiled a Jmeter use http interface testing tools.

  1.1 Development of the overall program interface test case

    The first step : analysis of the test requirements, and get the interface documentation provided by developers;

      Step two : from the interface documentation sorted out the interface test cases, which should include details of the parameters and parameter data, and a clear format and checkpoints;

      The third step : with the development of interfaces and test case review;

      Step Four : Combining development library, ready interfaces test case to the Senate and the parameter data, and organized into csv file format;

      Step five : Combining data document interface test case documentation and csv format, the interface to do the test case automation case development.

  1.2 Interface Automation application scenarios

    The current design automation interface test case has run two scenarios:

    (1) pre-test, develop self-test: after a new automated interface test case development is completed, the corresponding development interface directly to arrange for execution in the development of the local environment, once developed interfaces to confirm the completion of the development, begin to perform an interface test case basically you can get real-time test results, facilitate the development of instant decisions. (Development of local operating mode is to open the JMeter tool, JMX import file can be started.)

    (2) Regression Testing: Development of the local test is passed, or the entire demand for manual test is passed, the automated interface test cases do sorting, pick out the need to incorporate into the case regression testing, and re-prepare the test data in a continuous integration environment, and the case of continuous integration into the job in the past, these interfaces test cases for regression continuous integration platform needs to be configured to run automatically.

  1.3 interface test environment preparation

    Jdk1.6 or more: http://www.oracle.com/technetwork/java/javase/downloads/index.html

    Jmeter, Download: http://jmeter.apache.org/download_jmeter.cgi

    Download and install the plug-in address:  http://www.jmeter-plugins.org/

  1.4 Create Project

    1. Open Jmeter : Once you have downloaded Jmeter, jmeter.bat double-click the file in the bin directory:

    

    2. Add thread group : Right-click on the "Test Plan" -> Add -> threads (Users) -> thread group, add test scenarios set components, interfaces, testing is generally set to a "threads" the number of the test data set "cycles."

    

    3. Add "HTTP Cookie Manager ":

    

    4. Add "Default the Http Request " component, when access to the system under test has a unique domain name and port, this component good use:

    

    5. In the "HTTP Request Defaults" component configuration page, fill domain name and port system under test, to achieve http request packet and the specific version of the protocol type, in all thread group "HTTP Sampler" may default to this.

    

    6. Add "HTTP request" in the "thread group" in the Sampler

    

    7. In the HTTP page request is provided, the test interface entry details, including the request path, a request corresponding method, as well as with the parameter request list transmitted together:

    

    8.设置检查点:在被测接口对应的“HTTP 请求”上,添加“响应断言”:

    

    9.在设置页面上添加对相应结果的正则表达式存在性判断即可:

    

    10.添加监听器:方便查看运行后的结果

    

    运行结果:

    

  上述步骤完成了一个简单测试案例的创建,复杂测试案例均在此基础上扩展完成。使用Jmeter工具开发的接口测试案例,一个子系统建议放在同一个 “测试计划”中,流程测试可以通过“线程组”来区分,这样也便于设定不同的测试数据个数。比较独立的接口,可以统一放在一个线程组内,顺序完成测试。

  流程性接口的测试:如果要测试的接口可以组成一个流程,只需要顺序添加多个“HTTP 请求”的Sampler,各请求之间可以提取需要在上下文传递的数据作为参数,以保证流程中数据的一致性。

2. 接口测试持续集成

      对接口测试而言,持续集成自动化是核心内容,通过持自动化的手段我们才能做到低成本高收益。目前我们已经实现了接口自动化,主要应用于回归阶段,后续还需要加强自动化的程度,包括但不限于下面的内容:

  a) 流程方面:在回归阶段加强接口异常场景的覆盖度,并逐步向系统测试,冒烟测试阶段延伸,最终达到全流程自动化。

  b) 结果展示:更加丰富的结果展示、趋势分析,质量统计和分析等

  c) 问题定位:报错信息、日志更精准,方便问题复现与定位。

  d) 结果校验:加强自动化校验能力,如数据库信息校验。

  e) 代码覆盖率:不断尝试由目前的黑盒向白盒下探,提高代码覆盖率。

  f) 性能需求:完善性能测试体系,通过自动化的手段监控接口性能指标是否正常。

3. 接口测试质量评估标准

  a) 业务功能覆盖是否完整

  b) 业务规则覆盖是否完整

  c) 参数验证是否达到要求(边界、业务规则)

  d) 接口异常场景覆盖是否完整

  e) 接口覆盖率是否达到要求

  f)  代码覆盖率是否达到要求

  g) 性能指标是否满足要求

  h) 安全指标是否满足要求

Guess you like

Origin www.cnblogs.com/lisa2016/p/11670447.html