Testing with Maven

Starting from 9.2.0, you can use the Maven plug-in that is provided with the testing product to run tests as part of your Maven build. Apache Maven is a software build tool based on the concept of a project object model (POM).

Before you begin

  • You must have installed HCL OneTest Performance and set an environment variable that points to the installation location.

    For Mac OS, add an environment variable that points to the installation directory of the product: export TEST_WORKBENCH_HOME=/opt/HCL/HCLOneTest

    For Windows and Linux®, this environment variable is set when you install the product.

  • You must have installed Maven from V3.2.0 and set up an environment variable that points to the M2_HOME installation directory.

Introduction

To automate testing with Maven, you must configure a pom.xml file and launch your tests from the command line using Maven command. You can either use your own pom.file, or one that is delivered with the product.

Three files are delivered with the product installation in the <product install location>\HCLOneTest\maven2\ folder:
  • pomCustomSurefireSample.xml for Windows, Linux and macOS.
  • pomMojoExecPluginSample_Linux.xml for Linux and MacOS.
  • pomMojoExecPluginSample_Windows.xml for Windows.

The files contain all types of dependencies as well as arguments required to execute the test scripts. There are two methods to run tests with Maven.

Method 1

With this method, you can run one or several tests. If you use your own pom.xml file, edit it with the following lines and indicate which test(s) must be executed, otherwise, use the pomCustomSurefireSample.xml file as follows:
  • Copy the pomCustomSurefireSample.xml to a directory.
  • Edit the file and update the lines, enter the name and location of the test(s) that must be run. If the product is installed on a different drive or a different location, or if IBMIMSharedHCLIMShared location has been changed, enter the correct path to the HCLIMShared plug-in folder. For aftsuite attribute, you can input aft xml file as the parameter value.
    <!--test suite="testSources/Test1.testsuite"/-->
    	<!--test suite="Test2.testsuite"/-->
    	<test suite="C:/Runtimes/runtime-RptMvn/AA/testSources/Test2.testsuite" plugins="C:/Program Files/HCL/HCLIMShared/plugins"/>
    	<!--test    schedule="Schedule.testsuite" project="AA" workspace="C:/Runtimes/runtime-RptMvn" plugins="C:/Program Files/HCL/HCLIMShared/plugins"/-->
    	<!--test    suite="Test2.testsuite" project="AA" workspace="C:/Runtimes/runtime-RptMvn"/-->
    <!--test aftsuite="Test1.xml" project="AA" workspace="C:/Runtimes/runtime-RptMvn" plugins="C:/Program Files/IBM/IBMIMShared/plugins"/-->
  • Run Maven to update the pom file version command and use the plug-in version currently available on delivered repositories.
    mvn versions:update-properties -Dincludes=com.hcl.products.test.it -f pomCustomSurefireSample.xml
    
  • Run the test(s).
    mvn clean verify -f pomCustomSurefireSample.xml
    

    Fail safe reports are generated in the target directory, especially in target/failsafe-reports/<ProjectName>/<TestName>_<timestamp>.txt that will contain the screen capture of the execution.

In HCL OneTest Performance, if the HCL OneTest Server URL is configured in Window > Preferences > Test > HCL OneTest Server and Publish result after execution is set as Always in Window > Preferences > Test > HCL OneTest Server > Results, then the Reports information section on the Console page displays the names of the report along with its corresponding URLs. The report URLs are the HCL OneTest Server URLs where the reports are stored. You can access the report URLs to view the test execution information at any point of time.

Method 2

With this method, no Maven report is generated. If you use your own pom.xml file, copy the following lines and provide your parameter values. Otherwise, you can use the pomMojoExecPluginSample_Linux.xml or pomMojoExecPluginSample_Windows.xml sample file. Example with the pomMojoExecPluginSample_Windows.xml sample file:
  • Copy pomMojoExecPluginSample_Windows.xml to a directory.
  • Edit the file and update the arguments to reflect which test to execute. If the product is installed on a different drive or a different location, or if IBMIMShared location has been changed, update the two last lines with the path to the IBMIMShared plug-in folder.
    <argument>/C</argument>
                                <argument>${pt-plugin-cmdline}</argument>
                                <argument>-workspace</argument>
                                <argument>C:\Runtimes\runtime-RptMvn</argument>
                                <argument>-project</argument>
                                <argument>AA</argument>
                                <argument>-suite</argument>
                                <argument>Test1.testsuite</argument>
                                <argument>-plugins</argument>
                                <argument>C:/Program Files/HCL/HCLIMShared/plugins</argument>
    
  • In the argument tags, instead of the -suite option, you can use the -aftsuite option and input the aft xml file as the parameter value in the subsequent argument tag to run the AFT test. For example, in the preceding template, <argument>-suite</argument> <argument>Test1.testsuite</argument> can be replaced with <argument>-aftsuite</argument> <argument>aftfile.xml</argument>.
  • Run the test.

    For Windows:

    mvn clean verify -f pomMojoExecPluginSample_Windows.xml 
    

    For Linux or MacOS:

    mvn clean verify -f pomMojoExecPluginSample_Linux.xml