About automated testing, you know how much?

For the test network equipment, it must have the following situation you encountered.

1. The company's upcoming new software, the version has just finished testing the N test cases they have to run again!
2. Before making the company's products factory test, the same batch of N products, the same indicators to and fro repeatedly repeat the test! !
3. wanted time off to recover a drama, still busy testing tasks, cutting back and forth screen miserable! ! !

Well, then gave you an automated test.

First, the automated testing of language development

Do automated testing, first you have to consider what kind of scripting language to develop. Like Tcl language, which was created by John Ousterhout, the earliest known as the "Tool Command Language (Tool Command Language)". As a veteran of automated testing language, originally based on the integration of test systems developed. Tcl approachable, easy to learn, but powerful, often used for rapid prototyping, scripting, GUI and automated testing, etc.,. Tcl is an interpreted language, each statement directly to execute the order of explanation, process-oriented, need to be extended by the iTcl (incrTcl) version 8.6 package and provides object-oriented support, thread expansion pack to support multi-threading.

There come from behind Python language, but also sought after by everyone. In last year TOIBE published list of programming languages, Python language has lined up third, behind Java and C language, C ++ followed. Python an interpreted language, process-oriented and object-oriented, but also supports multi-threading. The reason we sought after is because Python language code is simple, simple syntax, the same function, Python may be just the amount of code in other languages ​​1/10 .. So Python language is also widely used in one system programming, artificial intelligence, Web development, big data and cloud computing, of course, the main automated test scripting language. In addition, there are also using Perl, C ++, Ruby, Java and other programming languages ​​as automated test.

Second, the advantages of automated testing

1, shorten the test cycle (test automation can effectively solve the problem of software products iterative regression testing time-consuming)
· fast test execution speed
* 7 * 24 hours for regression testing
can be no one on duty during the test ·

2, to avoid human error (in conventional tests based manual testing, manual testing completely dependent on human judgment and operation, which brought to the test human risk, particularly in the following points)
· the input data error
· Example execution error
· test report data error
• ignore the implementation of some use case
-ignore setting preconditions
· wrong understanding of the behavior of the system under test

3, easy access to coverage (in a good automation framework, you can better manage the progress of the test, after the completion of the implementation of automated test scripts, you can easily get code coverage, and then based on coverage analysis, test cases supplement)
as China leading network test equipment and solutions provider, believes and Thai new generation of software testing platform Renix, can provide comprehensive automated testing capabilities (5 categories) for you.
· Renix Tcl / Python API: easy to write scripts to automate testing;
· the To the GUI Tcl / Python: to facilitate the operation of the image interface, saved as an executable test scripts;
· XAT test automation software: easy centralized management of test scripts, connections test environment;
intelligent scripting tools (smart script): easy configuration of the test command;
* VIP service: according to your needs, customized automation services.

Tips: This article is a longer length, may take a moment of your time to read, but Xiao Bian strongly recommend that you take the time to read, because purely Xiao Bian worked hard to make, cures all kinds of unnecessary overtime!

Next, a detailed letter of introduction to all the Thai automated testing five major categories function.

A, Renix Tcl / Python API

Application automated test basis, test conditions preset, design and development testing step, the test result is determined and an output interface (API), the tester need to provide the API to support. At present, Tcl / Python automated test as popular development language, Renix also provides a corresponding Tcl / Python API, easy to testers write automated scripts.

In order to better understand the use of Renix API so that we, here at Python API for example, describes how the Python language to automate testing based on Renix platform. (If you are also interested in the Tcl language, you can contact A letter for your row worries doubts).

API Functions

Renix Python API functions are divided into five areas of the tester management:

1, the device management. The chassis including upgrades, test resource configuration (connection / disconnection of the chassis, occupying / relief port), the port configuration of physical properties (speed, duplex mode, flow control) and the like License management;

2, traffic management. Configuration comprising traffic load, traffic transmission mode configuration (Continue, Time, Burst), controlling the flow start and stop and the like;

3, protocol management. Comprising a configuration interface parameters, protocol configuration parameters, start and stop control protocol

4, the capture manager. Comprising capture port configuration, a filter configured to capture conditions to capture the configuration space, controlling start and stop capturing;

5, statistical management. Including subscription statistical view, statistics view, save the results and other data.

API overall architecture
Here Insert Picture Description

Automated testing is simply to achieve control of the tester via the API, API design is the use of object-oriented thinking. Like property tester management IP, port number, slot number, etc., to achieve a corresponding control class. Port as a resource for the most basic test, based on the port class is also derived from a variety of sub-categories, like the establishment of traffic, port physical attributes configuration, packet capture and other classes, inheritance belonging to the relationship between the two. As also begin to flow, hair flow is stopped, the establishment of the protocol simulation behavior, Renix API also provides a corresponding gain control class.

When tested, we are in a tree structure to organize test configuration items. Below, when we need to establish protocols 1, when the traffic flow 1 and 2, we need to define a good port 1 this object, go to the establishment of a protocol on the basis of traffic and port 1 on 1, 2 ports need to define the object on the basis of port 2 on the establishment of traffic to go 2.

When we create an object that inherits the basic root of four methods: delete, edit, get, execute, to carry out operations on objects created by these four methods to achieve the test configuration items configuration and editing.

By delete, you can delete the test configuration items and configuration items with all of its associated sub-;

, You can edit the content of the test configuration items through the edit;

By get, you can obtain the value of the test configuration item;

By execute, test operation may be performed CI.

And based on this, by the association between objects set_relatives; associated objects may be obtained by a method get_relatives; parent object can obtain the current configuration items by the test methods get_parent; and the obtaining sub-current test method of configuration items by get_children a list of node objects.

Here I will introduce several aspects of this case that use the API:
(1) create a test configuration item
can be configured to create test items through the appropriate class, it can be assigned to field configuration items at the same time created and must be specified when creating upper, upper point to legitimate parent object.

Below, to build the object by PORT_1 Port class in establishing port_1, upper points to its parent object is the root, while a Location Assignment '//10.1.5.11/1/1'. This object is created so port_1 completed.
Here Insert Picture Description
(2) delete the test item configuration
method for each test configuration item object has a delete, you can delete the test configuration items, but the point to note is to delete all configuration items will lead to the child associated with configuration items will be deleted.

Below, by port_1.delete () test port1 deleted configuration item, configuration item at this time if they exist stream_1 port_1 below, it will also be deleted.
Here Insert Picture Description
(3) modify the test configuration items
if you need to modify the test configuration items, there are two ways to achieve. The first may be modified by testing CI CI interfaces comes edit, modify the value in this way may be a plurality of fields at the same time, high efficiency; second, configuration can be modified directly via a member the test item CI , this approach has the advantage that simple and quick, clear syntax.

Below, by enabling stream_1.edit EnableSignature, FixedLength value and changed to 64. By stream_1.EnableSignature = True enabled EnableSignature; FixedLength by stream_1.FixedLength = 64 will change the value to 64.
Here Insert Picture Description
(4) obtaining a test configuration item
API value does not automatically synchronize with the local Renix the background, so to get the value of the test configuration needs to get through the get method. For this it is because once automatically synchronized, API will cache value after the synchronization, but also bring a lot of unnecessary performance overhead. Similarly, we can get the value of all the fields of test configuration items, you can also specify the value of one or more fields to be retrieved.

Below, (, 'FixedLength' 'EnableSignature ') and obtain the value EnableSignature FixedLength by stream_1.get. () Gets the value of all fields EnableSignature, FixedLength and RepeatCount by stream_1.get.
Here Insert Picture Description
(5) perform a test configuration items operating
in the API are all named after one operation Command at the end, we can create an action by the constructor and provide input parameters of the operation. Then an operation may be performed by the execute method. After the operation is performed may get some output parameters.

Below, to create a statistical view of operation of the flow created by CreateResultViewCommand (DataClassName = 'StreamStats') , and then perform operations to create statistical views through cmd.execute (). Obtained after statistical view is created cmd.ResultViewHandle can be assigned to view_handle as an output parameter, then call for other objects.
Here Insert Picture Description
Having said that, let's look at an example of a test script it. This example is whether the two ports to test the performance of the instrument from the rings are out of order or there is packet loss.

The first step: script design ideas
initialization API-> occupied port -> Configure Traffic -> Subscribe Statistics -> Start Test -> Stop Test -> Statistical Analysis -> judgment.

Step two: to write scripts
import modules need to use.
Here Insert Picture Description
Creating and occupancy test ports Port1, Port2.
Here Insert Picture Description
Source and destination MAC addresses transceiver port configured traffic flow configuration.
Here Insert Picture Description
Create and subscribe Stream Block statistics
Here Insert Picture Description
Here Insert Picture Description

To start the test, sending all traffic, after 10s, stop the test.
Here Insert Picture Description
According to the acquired statistical result analysis, the two flow check the number of packets transmitted and received are equal; check if there is flow loss two; check has two scrambled packet traffic
Here Insert Picture Description
according to a result of analysis, judgment, the test is Pass or Fail.
Here Insert Picture Description
The third step: get the associated object
we can set_relatives method will establish a link between the object, then the object can be obtained by get_relatives associated method. You may retrieve the current parent object by get_parent CI test method, and acquires a list of the child node object by the current test get_children CI method.

如下图,通过s1.set_relatives(‘RxPort’,Port_1,EnumrelationDirection.TARGET)将RxPort、Port_1、EnumrelationDirection.TARGET这几个对象关联起来。

通过port_1.get_children()方法获取当前测试配置项的所有子节点对象;通过port_1.get_children(relative_name=’StreamTemplate’)获取port1下类型为StreamTemplate的所有对象
Here Insert Picture Description
第四步:运行脚本
通过Win+R,输入cmd,打开cmd.exe(Windows系统适用);输入“cd ‘脚本所在路径’” ,进入脚本所在目录;输入“python ‘脚本名称’”,回车,执行脚本。
Here Insert Picture Description
第五步:查看测试结果
如下图,通过测试结果可以看到Stream_1发送了7492964个包,对端也接收到7492964个包,Stream_2发送了7492960个包,对端也接收到7492960个包,两条流量的收发相等;两条流量的丢包数都为0;两条流量传输过程中都没有产生乱序包。最后判断此次测试结果:Pass。
Here Insert Picture Description
二、GUI To Tcl/Python

GUI(Graphical User Interface)就是指图形用户界面,又称图形用户接口是指采用图形方式显示的计算机操作用户界面,在这儿特指Renix客户端界面。GUI To Tcl/Python目的在于将客户在GUI界面的配置和操作转化为可执行的自动化测试脚本。

测试的思想在于:客户在GUI界面连接机箱、占用端口、配置流量、配置负载等操作会保存为.xfcg文件,在Smart Script配置的开始发送所有流、停止所有流、订阅端口统计和2544/2889/3918套件测试等操作命令也会保存为.xfcg文件,然后对于这些操作和命令的调用代码就通过自动编写保存为test.py文件,最后当客户需要进行测试时,直接执行test.py文件即可。

另外,当你需要修改配置和操作时,可以通过Renix打开.xcfg文件修改配置和操作,然后再使用GUI To Python;或者就在test.py的文件中编写相应的代码完成对配置和操作的修改。这样大大减少了客户编写代码的时间,不仅提高了测试效率,对于代码不是特别精通的用户也都可以进行测试。毋庸置疑,这是代码量最小的自动化测试。

如下图,先在Renix界面上占用两个测试端口,每个端口各配置一条流量,帧长128字节,port1负载配置为50%(线速是1000M),port2的负载配置为100%;

Here Insert Picture Description

然后结合Smart Script,配置发送所有流、打流时长10s、停止发送所有流、等待3s、保存结果为1.db文件等命令;
Here Insert Picture Description
最后通过GUI To Python保存为可执行的自动化测试脚本。
Here Insert Picture Description
如下图,GUI To Python 生成的文件中,用户在GUI 界面占用的端口、配置的流量和在Smart Script配置的操作均被保存在.xcfg的配置文件,调用和执行配置文件的代码也被存为test.py。这样用户就可以直接通过执行test.py来完成自动化测试。
Here Insert Picture Description
我们运行test.py之后,可以看到,脚本已经测试成功,数据结果01.db的文件也已经在相应目录下保存,通过ResultAnalyzer可以打开文件查看结果
Here Insert Picture Description
Here Insert Picture Description
三、XAT自动化测试软件

XAT(Xinertel Automated Testing)是信而泰推出的自动化测试软件。
该软件旨在通过简单、快捷的方式实现对自动化脚本的集中测试和管理。可以通过该软件进行测试仪表和被测设备的连接,占用测试仪表的端口,将测试端口与测试脚本进行绑定,批量进行脚本测试。
软件界面会有测试结果的汇总,也会打印测试日志,便于测试失败时定位问题,更为重要的一点,通过该软件可以将测试记录一一保存在Excel文件中,包括之前的占用端口、测试配置、测试日志、测试结果等信息。节省了人工记录的时间,同时减少了人为记录可能带来的不必要的误差。操作方便、使用灵活,测试信息记录准确,可谓是自动化测试的好帮手。
Here Insert Picture Description
如下图,我们先通过XAT配置和占用IP地址为192.168.1.180测试仪的port1~8,然后在左下角的列表框中选中需要进行测试的一个或多个端口,选中192.168.0.180/1/4、192.168.0.180/1/6和192.168.0.180/1/8,鼠标右键,通过Combine To Group将选中端口组绑定成一个端口组,点击后在右下列表“端口组合”出现绑定的端口组。
Here Insert Picture Description
Here Insert Picture Description
完成配置端口后就可以点击“设置脚本”来选中需要执行的脚本。先打开脚本所在路径,在“搜索脚本”窗口会出现脚本文件,选中需要测试的脚本文件,鼠标右键,通过Add Script将选中的脚本添加到右下角的设置脚本列表;
Here Insert Picture Description
再次选中测试脚本,鼠标右键,通过Bind PortGroup将选中的脚本和“配置端口”设置好的端口组绑定,点击后,选中脚本和端口组绑定,并在右上角的测试套件中显示添加的脚本端口组合简称为“测试套件;
Here Insert Picture Description
The default test suite are checked in, left hook kit green and then if you do not perform the selected test suite script, the right mouse button, select the test suite is not performed when Unselect executed script. (Select Unbind Port Group, will test kit list to delete the selected test suite; choose select, the implementation of selected test suite script is executed);
Here Insert Picture Description
click on the "start" button in the toolbar to open all test execution "set port" - "test suite" in selected test suite. After starting the test, the "execution group port (1)" page, as shown below, the test results: show results after each test script execution completion information; Test Procedure: Each script step test execution, real-time display; "perform below port group (1) ": real-time display log log information performed; displayed in the status bar status in general performed
Here Insert Picture Description
after all the test execution is completed, the toolbar shows" export all test report button "before export reports, and then the menu bar - test report - setting the export path test report export report to the next path of execution, set up after the export directory click "" button after export all test reports, export the report is completed, view the report file. There in the Log folder detailed log information for each test scripts, test report word board in Report.doc, the Excel spreadsheet test was reported in TestResult.xlsx.
Here Insert Picture Description
The figure below is an Excel spreadsheet test report.
Here Insert Picture Description

Fourth, intelligent scripting tools (Smart Script)

Intelligent script is no code to write and test automation solutions perform. When a certain extent, the code white-saving, clear structure, flexible, user can easily get started.

Released three original articles · won praise 3 · Views 1687

Guess you like

Origin blog.csdn.net/XINERTEL/article/details/104521016