技术开发 频道

LR9.1测试ADO.net程序

  LR,首先安装LRVS2005IDEAddInSetup.exe插件,启动,选择Microsoft.net协议。录制刚才的程序后,LR,Action代码如下:

  namespace Script. {

  using LoadRunner;

  using Mercury.LoadRunner.DotNetProtocol.Replay;

  using System;

  using System.Data;

  using System.Data.SqlClient;

  public partial class VuserClass {

  public virtual int Action() {

  String connectionString_1;

  connectionString_1 = "Server = 10.72.128.135; Initial Catalog=QA_PTMES;User ID=DV_User;Pass" +

  "Word=Pass1234";

  lr.log("Event 1: new SqlConnection(connectionString_1);");

  SqlConnection_1 = new SqlConnection(connectionString_1);

  lr.log("Event 2: SqlConnection_1.Open();");

  SqlConnection_1.Open();

  lr.log("Event 3: new SqlDataAdapter(\"select * from TB_DIVISION\", SqlConnection_1);");

  SqlDataAdapter_1 = new SqlDataAdapter("select * from TB_DIVISION", SqlConnection_1);

  lr.log("Event 4: new DataSet();");

  DataSet_1 = new DataSet();

  lr.log("Event 5: SqlDataAdapter_1.Fill(DataSet_1, \"TB_DIVISION\");");

  // For data set named DataSet_1:

  // No tables found

  Int32RetVal = SqlDataAdapter_1.Fill(DataSet_1, "TB_DIVISION");

  // For data set named DataSet_1:

  \\此处在LR中显示的是TB_DIVISION的表结构和相应数据

  DATASET_XML(1);

  lr.log("Event 6: SqlConnection_1.Close();");

  SqlConnection_1.Close();

  return 0;

  }

  }

  }

  其实,可以看出,这个录制的脚本实际上跟源程序非常接近。

0
相关文章