SoapUI practice: automated testing, stress testing, continuous integration

 
 

Because of the project, I researched and used the SoapUI test tool some time ago to conduct self-test development api. The results of the research are shown below, hoping to help those who need it.

 

What is SoapUI?

SoapUI is an open source testing tool that checks, invokes, and implements functional/load/compliance testing of Web Services through soap/http. The tool can be used as a stand-alone test software, can also be integrated into Eclipse, maven2.X, Netbeans and intellij using plug-ins.

 

Installation of SoapUI

The download address , it is best to download the latest version of the installation package, because SoapUI is a testing tool developed based on java, the installation package of the previous version 3.0 does not integrate JRE, so you have to install and configure the java operating environment yourself.

 

Use of SoapUI

1. In the main interface File menu, click "New REST Project", fill in the url you want to test, according to the url in our project Teacher Site for example: https://teacher-test.grapecitydev.com :

 

Referring to the figure below, you need to enter the /Login/Login route in the Resource input box, and enter the query parameters accountName and password required for login in Params. 

2. Click the green button, SoapUI sends a login request, and you can see the result returned by the login request in the right frame.

According to the business requirements of the Teacher site project, after the Login request is sent, the SchoolItemChange interface must be sent to return the Token authenticated after the user has successfully logged in. The value of Set-Cookie in the following figure will be used in the Cookie attribute of the request header of the next GetOverview interface. : 

3. The next third request, GetOverview, is as shown in the figure below. Add the Cookie attribute in the Header box. The value is the Set-Cookie value returned by the previous request for SchoolItemChange: 

automated test

In fact, the invocation of the above three interfaces is just a simple test of whether the invocation of the interface is normal. If you want to automate the test of the invocation of the three interfaces, please see the following decomposition:

1. Right-click the Request request under each interface, as shown in the figure, select the "Add TestCase" item, and set the Test Case for the above three interfaces in turn. There are three TestCases, Login, SchoolItemChange, and GetOverview under TestSteps.
 

2. Have you noticed that there is a Set Cookie item under Test Steps, what is this for?

This is through the Groovy Script syntax to get the return value of the previous request (here is to get the return value "Set-Cookie" of the SchoolItemChange interface), and assign the "Set-Cookie" attribute value to the request header Cookie of the next request GetOverview , doesn't it fit in with Articles 2 and 3? ! This is a good solution for automated testing of interfaces, without copying and pasting dependent return values ​​between requests. 

3. Next, add an Assertion assertion to the tested interface. Click on the lower left corner to pop up the Add Assertion dialog box. According to the assertion annotation, select the required test point. For example, Response SLA indicates the expected response time after the request is sent:


 

Contains Assertion indicates that the string returned by the request contains the specified string. This assertion applies to comparisons with no more than 65535 characters, because Soapui is based on the java language, which is the maximum number of characters supported by the jvm: 

4. 为解决上述不能超过65535个字符的问题,则需要为接口添加 Script Assertion,如下代码,表示将本地文件 GetOverview 01.txt 中的内容与请求返回中 HtmlOfPartialView 属性的值进行对比,判断两者内容是否相等: 

5. 双击 Test Case,出现如下图,点击按钮,或者选中 Login 右键选择”Run from here”,则依次执行 Test Steps 步骤,如图所示,出现红色背景 Failed 字样,查看右下角 TestCase Log 框,可以看出是由于 Step 4 GetOverview 接口请求的响应时间 1272ms 大于断言中设置的时间 500ms: 

 

发送邮件功能

当你希望某个接口请求的结果以邮件方式通知给你时,如下图所示,右键 Test Steps -> Add Step -> Groovy Script,添加 Send Email 脚本,其中 Username 和 Password 分别是公司邮件服务器的账户和密码,Internet Address 即为接收的邮箱地址。

”${teacher-test#TestCase#Getoverview#Response}”的顺序依次为

Test Suite name # Test Case name # Test Step name # Response: 

 

压力测试

以上是功能性测试,接下来是压力测试,右键 Load Tests 创建测试用例,

Limit:60 即为压力测试的时间 60s,Thread 表示多线程,可以同时运行5个线程,Test Delay * Radom,表示随机延迟的时间数。

min 表示最小响应时间,max 表示最大响应时间,avg 为平均响应时间,last 表示上一次请求响应时间,cnt 表示请求数,tps 表示每秒处理请求数,bps 表示吞吐率,rat 表示错误率。

右键可以为请求添加断言,Max Errors 设置最大的错误数,Step Average 设置期望的平均时间,其他的依次类推: 

如下图,可以选择不同策略的负载和性能测试:

最常用的是简单策略(Simple),如果你想运行功能测试,并想在10秒内延迟5个线程,则 Threads 设置为5,延迟 1000s,随机延迟比率0.5(即将导致延误5至10秒)。 

方差策略(Variance),Threads 为方差的线程数量,Interval 为间隔设置所需的值。例如设置20个线程,间隔60和方差0.8,线程的数量将在第一个15秒从20增加到36,然后又减少到20,45秒后继续减少到4个线程,最后等到60秒时返回到初始值20。在统计图中我们很容易遵循这个方差: 

线性策略(Thread),从一个线程到另一个线程的数量的运行。它的主要功能是确定某些统计数据变化或事件发生时的水平,例如设置开始和结束线程值(例如1 - 10),并设置持续时间(此例中每个线程至少30秒)获得准确的测量数据: 

 

持续集成

在UI界面进行持续集成:右键项目名称 REST Project 1 -> 选择 Launch TestRunner,出现如下图,在 Basic Tab 页选择 TestRunner 安装路径:在 Reports Tab 页选择报告输出文件夹:

点击 Launch 按钮,自动执行测试项目。

 

通过执行命令进行持续集成,以管理员身份打开 Command Prompt 对话框,执行如下命令:

testrunner.bat -s'teacher-test' -cLogin -r -j -f'D:\Trivals\SoapUI\Logs' D:\Trivals\SoapUI\REST-Project-1-project.xml

该命令行的各个参数含义如下:

  • s : The TestSuite to run, used to narrow down the tests to run
  • c : The TestCase to run, used to narrow down the tests to run
  • r : Turns on printing of a small summary report (see below)
  • j : Turns on exporting of JUnit-compatible reports, see below
  • f : Specifies the root folder to which test results should be exported

其他更多的参数设置,请参考 SoapUI 官网地址:

https://www.soapui.org/test-automation/running-functional-tests.html

本文概要介绍了 SoapUI 工具的基本使用方法,也欢迎感兴趣的读者留言补充 SoapUI 的更多功能使用方法,大家共同学习进步。

转载请注明出自:葡萄城控件

 

葡萄城年末福利火热放送中

凡在 2017 年 12 月 31 日之前,购买葡萄城控件团队授权企业授权的用户,不仅可以享受到优惠的价格,还可获赠葡萄城技术专家根据客户项目需求提供的定制培训服务。老客户推荐新客户成单,也将获得“客户推荐双重感恩礼”。

了解更多:http://www.gcpowertools.com.cn/order/specialoffers.htm

 

关于葡萄城

葡萄城成立于1980年,是全球最大的控件提供商,世界领先的企业应用定制工具、企业报表和商业智能解决方案提供商,为超过75%的全球财富500强企业提供服务。葡萄城于1988年在中国设立研发中心,在全球化产品的研发过程中,不断适应中国市场的本地需求,并为软件企业和各行业的信息化提供优秀的软件工具和咨询服务。 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326194251&siteId=291194637