Applies to TestLeft 4.20, last modified on September 11, 2019

You can include TestLeft test code into unit tests and run them by using various unit testing frameworks. This topic describes how to run TestLeft tests by using the TestNG framework.

About

You can include the TestLeft library to your test project, and create TestNG tests that include TestLeft test code. Then, you will be able to run those tests the same way you run native TestNG tests.

Requirements
  • Java 8 or later.

  • TestNG unit testing framework.

  • To create TestLeft tests, you will need the TestLeft library.

    By default, the library is shipped with TestLeft and resides in the <TestLeft>\API\Java folder.

    Note: You can create your tests on any computer that has access to the TestLeft library file, including those running under a non-windows operating system. However, the tests you create can run only under the Windows operating system. In addition, it's only on the Windows operating system that you can use the UI Spy, a TestLeft tool that allows exploring the internal hierarchy of a tested application.
  • To run tests, you must have TestLeft installed.

Creating and Running a TestLeft Test
  1. Open your test project and add the TestLeft library to it. By default, the library resides at –

    <TestLeft>\API\Java\

    The way to add the reference depends on your project type. For example, if you use Maven, add the following dependencies to your pom.xml file:

    pom.xml


    <dependencies>
      …
      <dependency>
        <groupId>com.smartbear.testleft</groupId>
        <artifactId>testleft</artifactId>
        <version>4.20</version>
        <scope>system</scope>
        <systemPath>C:/Program Files/SmartBear/TestLeft 4/API/Java/testleft-4.20.jar</systemPath>
      </dependency>
      <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.2</version>
      </dependency>
      <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-compress</artifactId>
        <version>1.15</version>
      </dependency>
      <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.3.4</version>
      </dependency>
      …
    </dependencies>

    These are the TestLeft library and the libraries that it requires to work correctly.

  2. Make sure that your project includes references to the libraries of the unit testing framework you will use to run TestLeft tests. For example, TestNG:

    pom.xml


    <dependencies>
      …
      <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.7</version>
      </dependency>
      …
    </dependencies>

  3. In your project, open a TestNG test to which you want to add TestLeft test code or create a new one.

  4. Import the needed TestLeft packages to your test:

    Java

    import com.smartbear.testleft.*;
    import com.smartbear.testleft.testobjects.*;
  5. Add the needed test instructions to tests. To learn how to create test instructions, see Creating TestLeft Tests.

  6. Build the project and run the tests.

    If you use Eclipse, IntelliJ IDEA, or NetBeans, you can run the tests directly from the IDE. For example, to run tests from IntelliJ IDEA IDE:

    Note:To run TestNG tests from IntelliJ IDEA IDE, you must have the TestNG-J plugin installed and enabled (the plugin is shipped with IntelliJ IDEA by default). To learn more, see the IntelliJ IDEA documentation.
    • Open your test code for editing, right-click anywhere in the editor and then click Run:

      Running TestLeft tests: Run a TestLeft from IntelliJ IDEA Project Explorer

      Click the image to enlarge it.

    – or –

    • Right-click the needed test class in the Project panel and then click Run.

    – or –

    • Select Run > Run from the main menu and then select the needed test from the Run list.

    – or –

    • If you use Maven, in the Maven Project panel, right-click the Lifecycle > test item and then click Run.

    – or –

    • You can also compile your tests and run them from the command line. For example:

      java -classpath "C:\testng\*;C:\Work Folders\TestLeftProject\target\test-classes;C:\Program Files\SmartBear\TestLeft 4\API\Java\testleft-4.20.jar;C:\gson\*;C:\apache\commons\commons-compress\*;C:\objenesis\*;C:\apache\httpcomponents\*;C:\apache\httpcomponents\httpcore\*;C:\commons-logging\*;C:\commons-codec\*" org.testng.TestNG -testclass com.example.test.TestLeftProject.SampleTestLeftTest

  7. During the test run, TestLeft will execute the test instructions.

  8. Information on all user actions that TestLeft simulates is stored to the test log. The TestLeft test log is stored separately from the TestNG native test log, in a temporary folder. By default, after the test run is over, TestLeft test log is deleted. You can add instructions to your TestLeft tests that will export the TestLeft results to an external file. To learn how to do it, see Saving Test Logs. After the test run is over, you can view the TestLeft log.

See Also

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

Highlight search results