Performance test script development (Lr.net control)

Source: Internet
Author: User

Copyright NOTICE: This article for brother even it education original article, without Bo Master permission not reproduced.

In the performance testing process, the most expensive experience is the process of writing performance test scripts, in most of the test tools are recorded in the way, through recording to generate scripts, and then modify as needed, as well as parameterization. Sometimes in order to be able to complete a function of the script, the recorded script will need to "big surgery", to the scripting people have a lot of trouble.
This article introduces a new way to generate scripts, which is very convenient for ISVs (independent software developers) and some code-based test vendors, especially if some C/s structures are more effective in this way. This paper introduces how to use LoadRunner add_in to develop scripts, if you want to use this approach is necessary to have a few prerequisites: to have the test program's source code is tested program architecture to be clear, for some of the product is not good enough for layering, it is not appropriate to use this method. The person who writes the script wants to understand the use of LoadRunner. Of course, LoadRunner and plug-ins need genuine.

First, plug-in installation

first install order not Wrong, install the appropriate development software before installing the plugin, for example: visual 
Basic or Visual Studio. NET or JBuilder. The plugin for LR is used in the IDE environment of the corresponding software. Supported locales here first explain the languages that plug-in can support, what I know is the ability to support visual Basic or Visual Studio. NET or JBuilder, each using a similar approach, this article focuses on the. NET environment as Where to use. Installation process generally loadrunner the installation disk is divided into two parts, part of the LoadRunner main functions include script generator, Controller, Analyzer, Agent and so on. The other part is LoadRunner plug-ins, which include a variety of monitoring plug-ins, as well as the IDE plug-ins, we want to use the IDE plug-in.  
650) this.width=650; "title=" "src=" http://img.blog.csdn.net/20150801162147069 "alt=" here write a picture describing "style=" border:0px; "/> 
Click to enter the add-ons directory, where we can select the relevant content, we use the directory  
is: ... \additional components\ide Add-ins\ms Visual Studio. NET, installation files:  
lrvs2005ideaddinsetup.exe 
650) this.width=650; "title=" "src="/HTTP/ img.blog.csdn.net/20150801162204338 "alt=" here to write a picture describing "style=" border:0px; "/>

The installation process is as simple as any other software and does not need to be described. After installation, you need to restart your computer,
Be aware that all IDE environments are shutting down during the installation process.

Second, plug-in use

After installation, let's look at what the IDE has become!!
. NET Environment:
650) this.width=650; "title=" "src=" http://img.blog.csdn.net/20150801162228159 "alt=" here write a picture describing "style=" border:0px; "/ >
A menu of "VUser" will be found in the menu. This menu is the main content we use.
In addition, loadrunner corresponding objects are added to the object library. There is no difference between the use of these objects and the use of other objects in the software. These correspondence can be identified by LoadRunner, and can also be concurrency-safe.
How do we build a performance test project after we have successfully installed the plugin? The next section is divided into sections that describe how to use these menus.

Third, the project establishment

After the plugin has been successfully installed, there will be an extra option in the new project, and we need to build the project.
650) this.width=650; "title=" "src=" http://img.blog.csdn.net/20150801162207001 "alt=" here write a picture describing "style=" border:0px; "/ >
In. NET, you can support vb.net, vc.net, and the C # language, and should be able to meet the needs of normal use.
Once the project is established, the development environment will automatically create some scripts, and you will see a very familiar frame structure.
Take C#.net as an example:
650) this.width=650; "title=" "src=" http://img.blog.csdn.net/20150801162407527 "alt=" here write a picture describing "style=" border:0px; "/ >
Like the LoadRunner VU Generator tool, the script is divided into three parts, namely Initialize (), Actions (), Terminate (). In the list on the right we can see that there is only one Vuserclass class. Like many C # programs, you can modify the name, add classes, and so on, but the default three function names and properties do not modify, just fill in the content in the appropriate location. After we set up the project, we look closely at the catalog and what the difference is between the catalog of the project and the ordinary C # program.
The first thing to do is compile the project, generate the. dll file, and then we will interpret the project directory. We can see from the figure below that there are several new files in addition to the generic files generated by the C # project.
650) this.width=650; "title=" "src=" http://img.blog.csdn.net/20150801162449194 "alt=" here write a picture describing "style=" border:0px; "/ >
. The USR file is a file that is automatically generated by the LoadRunner plugin, which is the script to be selected in the LR controler tool. That's the performance test script we're going to use eventually, and we'll talk about calling that file later. Open with Notepad. USR file:
650) this.width=650; "title=" "src=" http://img.blog.csdn.net/20150801162521299 "alt=" here write a picture describing "style=" border:0px; "/ >
We can clearly see that the file is not actually an implementation of the script, but rather a project header information file, which records the classes and files that the performance test script needs to support, the collection point name of the script, the transaction name, the CLSID, and so on. Describes the main content contained in the script, which is associated with other files. If you are a master, you can directly modify this file to achieve your goal.
LOADRUNNERVUSER.PRM this file records all parameters in the script, as well as the properties of the parameters, and the value of one parameter is recorded in the following. dat file.
650) this.width=650; "title=" "src=" http://img.blog.csdn.net/20150801162617553 "alt=" here write a picture describing "style=" border:0px; "/ >
Songresource.dat file, the Songresource.dat file is a parameter file that indicates that there is a parameter in the performance test script
Number is called Songresource. To open this file, we can see that the value of the parameter is recorded in this file.
Each row is a value, just like the parameters of the VU Generator tool. The. dll file, which is the file that the script needs to support, is required to have this file on any Generator machine, so this file It is important that the results of each compilation be deployed on all Generator machines.

Iv. Script Writing

After the framework is generated, we need to add the relevant code based on the content of the test, and the functions described below are
C # As an example, other languages are not much worse.
Let's assume a scenario where you want to test 100 users logging in to the system at the same time. The following will be done around this theme.
First, the object is created, regardless of the content you use:
Loadrunner.lrapi LR;
LR = new Loadrunner.lrapi ();
1. Business
Transactions are the most central unit of testing, so the creation of a transaction is very important, and the following is the process of defining a transaction.
Loadrunner.lrapi LR;
LR = new Loadrunner.lrapi ();
Lr.start_transaction ("Syslogin"); Transaction start
Client_syslogin ("servername", "username", "UserPassword", "2005-1-12");
Lr.end_transaction ("Syslogin", LR. PASS);//End of transaction
The start and end of a transaction is essentially the same as the VU Generator tool script, and it is important to note that the content that is called in the middle should be the component that is called by the application being tested, so that the script being written is testing the application, otherwise it does not explain any problems. For example: The Client_syslogin function above is the function used by the application.
This requires a higher level of application testing and a clear hierarchy of application points. Let's take a look at the application
How the program is implemented:
private void Buttonlogin_click (object sender, System.EventArgs e)
{
String srvname,username,userpws,logindate;
Srvname=text1.text;
Username=text2.text;
Userpws=text3.text;
Logindate=text4.text;
Client_syslogin (srvname, username, USERPWS, logindate);
}
private void Client_syslogin (Srvname, username, USERPWS, logindate)
{
Connect to the database;
Determine if the user name and password are correct;
return user permissions;
}
Obviously, the application separates the business logic judgment from the UI layer, so we have a clent_syslogin function
The test is our ultimate goal.

Test the application, or you will not be able to describe any problems. For example, the Client_syslogin function above is the application process
The function used by the order.
This requires a higher level of application testing and a clear hierarchy of application points. Let's see.
See how the application is implemented:
private void Buttonlogin_click (object sender, System.EventArgs e)
{
String srvname,username,userpws,logindate;
Srvname=text1.text;
Username=text2.text;
Userpws=text3.text;
Logindate=text4.text;
Client_syslogin (srvname, username, USERPWS, logindate);
}
private void Client_syslogin (Srvname, username, USERPWS, logindate)
{
Connect to the database;
Determine if the user name and password are correct;
return user permissions;
}
Obviously, the application separates the business logic judgment from the UI layer, so we have a clent_syslogin function
The test is our ultimate goal.
2. Parameters
The above describes how transactions are defined and implemented, and next we talk about how to parameterize in code,
This process is similar to defining a generic variable, except that the value of this variable is derived from the data in the parameter table. We continue to
Continue with the above example:
Loadrunner.lrapi LR;
LR = new Loadrunner.lrapi ();
Lr.start_transaction ("Syslogin"); Transaction start, transaction name Syslogin
/*
To take the relevant value out of the argument list, we assume that the argument list already exists.
Srvname_parm,username_parm,userpws_parm,logindate_parm a few variables, each of which has
100 values
*/
String srvname,username,userpws,logindate
Defining variables
Srvname = Lr.eval_string ("{srvname_parm}");
Username = lr.eval_string ("{username_parm}");
USERPWS = Lr.eval_string ("{userpws_parm}");
Logindate = Lr.eval_string ("{logindate_parm}");//Remove the correct data from the argument list to the variable

V. Deployment of the Environment

When we have these scripts, the next step is how to run them.
For scripts developed with. NET, it's not that troublesome, just a simple copy, but another problem for. NET users. When we develop. NET applications, most of the time by reading an EXE file corresponding to the config file to get the relevant configuration information, then what is the. exe file at this time? Can tell you that the LoadRunner Controller tool in the run script is called the. exe is the Mdrv.exe program, that is, if your program needs to read the configuration file exe, you need to put this configuration file and Mdrv.exe file in a directory: .... \hp\loadrunner\bin

VI. matters of caution

Here are some of my experience, everyone in the use of the time to pay more attention to the place.
1, named because the generated files are mainly engineering projects and DLL files, must have a named specification, first of all
cannot be duplicated, followed by the names of the classes that are directly related to the generated. dll.
2, do not write the statement can not be concurrent
From the above explanation you can see, we write the test script is not human interaction, and all scripts are written for concurrent performance testing, so if there is no concurrency in the script of functions and methods, will be error, is generally memory errors, this is hoped that everyone must pay attention to the general mining A. dll, written in a thread-safe manner, can be easily generated by writing libraries directly and writing files directly.
3, refers to the concurrency can not mention the log because our script is a class function, there is no interface, so everyone in the debugging time will feel more difficult, then how to solve the problem?

In general we will have two ways:
One is to use the function provided by LoadRunner to return the results to the relevant log
The other is the use of their own writing log, the record needs to record content. At this point you need to be aware that the operation of writing files is not concurrent, so you need to deal with it again.
4. The following error may occur during the execution of the scene:

Case Description: Error:cannot start Transaction "XXXXX". This vuser already started a
Transaction with the same name, and have not yet processed the corresponding
Lr_end_transaction statement.

Problem Analysis: Because the error prompt is transaction, so the main thing to see the script part of inserting things, according to the hint can be concluded that the program entered the Lr.start_transaction, before the end_transaction is abnormal, so there is no implementation end_ Transaction, the error will be reported, this analysis may be difficult to think of, there is a simple
The way to do this is to execute the script and then look at Replay Log, at which point you can see a red exception with the following:
Error:vuser started transaction "XXXXX", but do not reached a corresponding end
Transaction statement. The transaction ended automatically with status ' fail '.

Solution: Just put the beginning and end of things on the outside of the Try/catch.

Scenario Description: A large number of transactions failed with no error message during scenario execution.

Problem analysis: Since the execution of the scene has generated the same name transaction, so that the transaction is not finished before the start of the business.

WORKAROUND: The transaction name in both functions is parameterized for the start and end of the transaction. As shown below:

Lr.start_transaction (Lr.eval_string ("{transaction_name}"));

Lr.end_transaction (Lr.eval_string ("{transaction_name}"), Lr_auto);

The above is the introduction of how to use another way of performance testing, this test method is not for all production
Product all the procedures are suitable, we can choose according to their own needs.


Performance test script development (Lr.net control)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.