首先需要安裝 lr的.net add-in ,在開發(fā)環(huán)境編寫代碼,做數(shù)據(jù)庫連接,然后調(diào)用執(zhí)行存儲(chǔ)過程。
裝好以后,打開程序,應(yīng)該看到菜單欄里多了一個(gè):
然后添加一個(gè)lr項(xiàng)目:

之后就可以編碼了,我寫了個(gè)代碼,如下:
using system;
using system.runtime.interopservices;
using system.componentmodel;
using system.data;
using system.data.oracleclient;
using shangxin.data;
using system.collections;
using system.web;
namespace loadrunneruser
{
/// <summary>
/// summary description for vuserclass.
/// </summary>
[classinterface(classinterfacetype.autodual)]
public class vuserclass
{
loadrunner.lrapi lr;
protected system.data.oracleclient.oracledataadapter oracleda;
protected system.data.oracleclient.oraclecommand loadcommand;
protected system.data.oracleclient.oracleconnection oracleconnection;
public vuserclass()
{
// loadrunner standard api interface :: do not remove!!!
lr = new loadrunner.lrapi();
}
protected system.data.oracleclient.oracleconnection getoracleconnection()////sqlconnection
{
if (oracleconnection==null)
oracleconnection=new system.data.oracleclient.oracleconnection();
oracleconnection.connectionstring="user id=test;password=write;data source=escalade";
return oracleconnection;
}
// ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int initialize()
{
// to do: add virtual user's initialization routines
return lr.pass;
}
// ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int actions()
{
try
{
lr.start_transaction("testgetwithdraworderbycode");
system.data.oracleclient.oracleconnection conn = new oracleconnection("user id=test;password=write;data source=escalade");
system.data.oracleclient.oraclecommand comm = new oraclecommand();
comm.connection = conn;
comm.commandtext = "bill.getwithdraworderbycode";
comm.commandtype = commandtype.storedprocedure;
//輸入?yún)?shù)
system.data.oracleclient.oracleparameter param1=comm.parameters.add("v_code",oracletype.varchar,20);
param1.direction = parameterdirection.input;
param1.value ="th15";
//輸出參數(shù)
system.data.oracleclient.oracleparameter param2=comm.parameters.add("retcursor",oracletype.cursor);
param2.direction = parameterdirection.output;
datatable dt = new datatable();
oracleda = new system.data.oracleclient.oracledataadapter();
oracleda.selectcommand = comm;
oracleda.fill(dt);
int icount=convert.toint32(dt.rows.count.tostring());
if(icount>0)
lr.end_transaction("testgetwithdraworderbycode",lr.pass);
else
lr.end_transaction("testgetwithdraworderbycode",lr.fail);
}
catch(exception ex)
{
string error = ex.message;
}
return lr.pass;
}
// ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int terminate()
{
// to do: add virtual user's termination routines
return lr.pass;
}
}
}記得添加必要的引用,具體使用靈活掌握吧
新聞熱點(diǎn)
疑難解答
圖片精選