首先需要安裝 LR的.NET ADD-IN ,在開發環境編寫代碼,做數據庫連接,然後調用執行存儲過程。
裝好以後,打開程序,應該看到菜單欄裡多了一個:
然後添加一個LR項目:
之後就可以編碼了,我寫了個代碼,如下:
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;
//輸入參數
System.Data.OracleClient.OracleParameter param1=comm.Parameters.Add("V_CODE",OracleType.VarChar,20);
param1.Direction = ParameterDirection.Input;
param1.Value ="TH15";
//輸出參數
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;
}
}
}
記得添加必要的引用,具體使用靈活掌握吧