Running TestLeft Tests from MSTest Tests

Applies to TestLeft 15.40, last modified on March 17, 2022

You can include TestLeft test code in unit tests and run them by using various unit testing frameworks. This topic describes how to run TestLeft tests by using Unit Testing Framework in Visual Studio.

About

TestLeft provides templates for Visual Studio that make it easier to create and run unit tests that run TestLeft code. You will be able to run those tests in the same way you run native Visual Studio unit tests.

Requirements

The templates are available only for Visual Studio projects that target .NET Framework version 4.5 or higher.

Note: If your project targets an earlier version of .NET Framework, or if you use another unit testing framework, you can add TestLeft code to your unit tests and run them by using your unit testing framework manually, without using the templates.
Creating and Running a TestLeft Test
  1. Add a TestLeft MSTest Project to your solution:

    • In Visual Studio’s Solution Explorer, right-click the solution and then click Add New Project.

    • In the Add New Project dialog, select the Test category and then select the TestLeft MSTest Project type.

      TestLeft MSTest Project Template

      Click the image to enlarge it.

    • If needed, specify the project name and location.

    • Click OK to add a project.

    • Visual Studio will add a TestLeft MSTest Project to your solution.

      TestLeft MSTest project in Visual Studio

      Click the image to enlarge it.

  2. The project includes a reference to the SmartBear.TestLeft.dll library and defines a UnitTestClassBase class.

    The class specifies methods to call before, during, and after running a test. It also includes instructions to export TestLeft test results after the testing is over.

    Use the class to create tests:

    C#

    [TestClass]
    public class TestLeftTest : UnitTestClassBase<TestLeftTest>
    {

      …

      [TestMethod]
      public void TestMethod1()
      {
        …
      }

      …

    }

    Visual Basic .NET

    <TestClass()>
    Public Class TestLeftTest : Inherits UnitTestClassBase(Of TestLeftTest)

      <TestMethod()>
      Public Sub TestMethod1()

        …
      End Sub

      …

    End Class
  3. Add the needed test instructions to tests. To learn how to create test instructions, see 2. Write Test Code.

  4. Build the project and run the tests.

    To run tests directly from Visual Studio:

    • Open the Test Explorer panel. It will list all tests in your solution.

    • In the panel, select the needed tests, right-click the selection and then click Run Selected Tests.

    • Visual Studio will run the tests.

    You can also run the tests by using the MSTest utility, for example:

    <MSTest.exe> /testcontainer:TestLeftTestProject1.dll /test:TestMethod1

    For information on the MSTest command line and other command-line arguments you can use, see the MSTest.exe Command-Line Options article in the MSDN library.

Important

The TestLeft MSTest test template has a method that saves test results to the test results folder automatically after the test run is over.

MSTest clears the test results folder if the test passes. If the test fails, the test results are stored. This allows reducing the amount of disk space the test logs occupy.

To store TestLeft test results regardless of whether the test has passed or failed, you can do one of the following:

  • Add test commands that will store TestLeft test results to another location. To learn how to export the TestLeft test log, see Saving Test Logs.

– or –

  • Configure MSTest not to clear the results of passed tests. You can find information on how to do this in the MSDN Library (the online version is available at https://msdn.microsoft.com/en-us).

See Also

Running TestLeft Tests From Unit Testing Frameworks
Using TestLeft
Writing Test Code

Highlight search results