51Testing软件测试论坛

标题: 利用loadrunner测试ORACLE存储过程的性能 [打印本页]

作者: zzr_999    时间: 2007-5-15 23:44
标题: 利用loadrunner测试ORACLE存储过程的性能
首先需要安装 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=testassword=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=testassword=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;
  }
}
}

记得添加必要的引用,具体使用灵活掌握吧




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2