Create a Vuser Script in Visual Studio

LoadRunner's basic IDE add-ins for Visual Studio let you create a Vuser script in Visual Studio in VB, C++, or C#.

Although .NET-based and Java protocols support creating threads, we recommend that you do not use background threads in real load testing scenarios because:

  • Threads can degrade tests scalability.

  • Threads can affect performance measurements.

  • The utility functions' behavior is undetermined if called from any thread except the Vuser main thread which runs the vuser_init, Action, and vuser_end actions. This applies to all functions named lr*.

To create a Vuser script in Visual Studio:

  1. Install the IDE add-in for your version of Microsoft Visual Studio from your LoadRunner installation package's Additional Components folder. For example, Additional Components\IDE Add-Ins\LRVS<version>IDEAddInSetup.exe.

  2. In Visual Studio, select the appropriate template from the Installed Templates LoadRunner VB|C++|C# .NET Vuser. Visual Studio creates a new project with one class and a template for a Vuser, and the script file, <name>.usr. The template contains three sections, Initialize, Actions, and Terminate.

    The following example shows a Visual C# template:

    public int Initialize()
          {
              // TO DO: Add virtual user's initialization routines
                return lr.PASS;
          }	
          public int Actions()
          {
              // TO DO: Add virtual user's business process actions
              return lr.PASS;
          }
          public int Terminate()
          {
              // TO DO: Add virtual user's termination routines
              return lr.PASS;
          }
    
  3. Add code to the template, in the TODO sections.

  4. Open the Object Browser (View menu). Expand the LoadRunner node (for example Interop.LoadRunner) to see the LoadRunner elements. Add the desired elements to your script, such as transactions, rendezvous points, and messages.

  5. Expand the Toolbar menu, Vuser, and enhance your script with runtime settings and parameters. For more information, see the runtime settings General > Run Logic or the Parameter List Dialog Box.

  6. Use the Vuser menu to replay the script and test its functionality.

  7. Select Vuser > Create Load Scenario, to create a LoadRunner scenario using this .usr file.

  8. You can also build the LoadRunner project as a DLL file, which will be saved in the same folder as the project. You can reference this DLL directly from a LoadRunner scenario.

Back to top