jenkins+ant+jmeter自动化接口测试框架搭建

接口测试是测试中极为重要的环节,它所处的位置,有别于单元测试和功能测试,在单元测试之后,在功能测试之前。每个接口都能代表某种功能,功能就有输入与输出。检验输入输出、各参数的取值以及异常情况,对于单元测试来说,是一个补充,因为往往单元测试是以类、以方法来测试的。对于功能测试来说,是一个护盾,在经过接口测试的验证后,能更高程度的保证功能点的正常执行。若能让接口定时测试或项目部署后自动进行验证(等同于回归测试),显得极为方便、快捷,能更多地节省出时间,进行其他工作的处理。

基于以上的目的,搭建一套自动化接口测试框架显得尤为重要,在市面上测试接口的工具有很多,比如:LR、jmeter、SoapUI、Gatling、Postman等。打包构建的工具有Make、Ant、Maven等。CI持续集成的工具有Jenkins、Hudson等。这些工具各有千秋,只要能实现最初的目的,不管使用什么工具都是一个辅助作用而已。而我选择的工具是Jenkins+Ant+Jmeter作为自动化接口测试框架的搭建。为啥使用这套框架是由于最早时Jenkins上并没有maven插件,Jmeter设计打包构建测试的案例里用的就是Ant,基于以上背景,所以使用这套工具有天然的成分在里面。

下面开始搭建这套框架的讲解。工欲善其事,必先利其器,在搭建之前,jenkins、ant、jmeter的linux版本包要准备好。Java版本:1.8.0_131;Ant版本:1.9.9;Jenkins:2.65,并且都已安装至Linux服务器上。环境变量设置如下:

 

 

在windows上打开Jmeter,把脚本编辑完成,能成功执行并返回结果。

在windos安装好Ant,新增其环境变量。

 

编辑Jmeter在这个目录下D:\Program Files (x86)\apache-jmeter-2.13\apache-jmeter-2.13\extras的build.xml文件。因为ANT打包构建就是依赖这个文件做处理的,这文件如何编辑如下:

----------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF8"?>

<!--

Licensed to the Apache Software Foundation (ASF) under one or more

contributor license agreements. See the NOTICE file distributed with

this work for additional information regarding copyright ownership.

The ASF licenses this file to You under the Apache License, Version 2.0

(the "License"); you may not use this file except in compliance with

the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

-->

<project name="ant-jmeter" default="all">

<description>



Sample build file for use with ant-jmeter.jar

See http://www.programmerplanet.org/pages/projects/jmeter-ant-task.php



To run a test and create the output report:

ant -Dtest=script



To run a test only:

ant -Dtest=script run



To run report on existing test output

ant -Dtest=script report



The "script" parameter is the name of the script without the .jmx suffix.



Additional options:

-Dshow-data=y - include response data in Failure Details

-Dtestpath=xyz - path to test file(s) (default basedir).

N.B. Ant interprets relative paths against the build file

-Djmeter.home=.. - path to JMeter home directory (defaults to parent of this build file)

-Dreport.title="My Report" - title for html report (default is 'Load Test Results')



Deprecated:

-Dformat=2.0 - use version 2.0 JTL files rather than 2.1



</description>

<!-- 定义变量并赋值,能够减少配置工作量,后面会调用到-->

<!-- 定义jmeter的工作目录,与%JMETER_HOME%指向同一个目录-->

<!-- ${basedir}当前目录的意思
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值