Develop a unit test using Visual Studio (NUnit test)

The LoadRunner Add-in for Developers enables you to create an NUnit test in Visual Studio for use with LoadRunner Professional.

Note:  

  • To install a Visual Studio add-in, Visual Studio must be installed in the default location.
  • To run your NUnit test from Controller, make sure that the NUnit framework is installed on Controller and load generator machines. Define the path to the installed NUnit framework in the Options dialog box. For details, see Options dialog box.

To create an NUnit test in Visual Studio:

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

  2. In Visual Studio, open your unit test. This test should comply with the following guidelines:

    • It is a class library

    • There is a reference to the NUnit library, nunit.framework.dll, using nunit.framework. This must have the same NUnit framework version as the one installed on Controller and load generator machines.

    • At least one of the classes in the project should be a TextFixture (using the [TextFixture] annotation)

  3. In the code, instantiate the LoadRunner API function.

    Example: private LoadRunner.LrApi lr = new LoadRunner.LrApi();

  4. Add the following call init method before the LoadRunner API function:

     [OneTimeSetUp]
            public void Init()
            {
                DriverWrapper.Driver.init();
            }

    The test code should then look like this:

    using System;
    using NUnit.Framework;
    using System.IO;
    
    namespace nunit2xTest
    {
        [TestFixture]
        public class UnitTest1
        {
            [OneTimeSetUp]
            public void Init()
            {
                DriverWrapper.Driver.init();
            }
    
            [Test]
            public void TestMethod1()
            {
                LoadRunner.LrApi api = new LoadRunner.LrApi();
                api.start_transaction("test");
                api.think_time(10);
                api.output_message("This is test");
                api.output_message("SingSong");
                api.end_transaction("test", 0);
                api.output_message("\n----------------------------");
            }
        }
    }
  5. Select DevOps Vuser > Add LoadRunner API Reference to add protocol-specific or general API functions to your test. Alternatively, select Add LoadRunner API Reference from the context menu. Add LoadRunner Professional functionality, such as transactions, think time, and messaging.

  6. Build the LoadRunner Professional project as a DLL file, to be saved in the same folder as the project.

  7. Select DevOps Vuser > Run Vuser to run the test with the LoadRunner Professional engine. In the Visual Studio Output window, select Show output from: LoadRunner Information to view the runtime data.

  8. (Optional) Add the DLL as a unit test to an existing or new LoadRunner Professional scenario. For details, see New Scenario dialog box.

Back to top

See also: