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 Rational® Functional Tester 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/IBM/SDP

    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>\SDP\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. For information on the supported arguments, see Supported options in Maven.

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 IBMIMShared location has been changed, enter the correct path to the IBMIMShared plug-in folder. For aftsuite attribute, you can input aft xml file as the parameter value.
    <!--test suite="soa" project="AA" plugins="C:/Program Files/IBM/IBMIMShared/plugins"/--> importzip="c:/MavenTrial/Tests.zip" workspace="C:/TmpDir"/--> <!-- To publish, the user need to place the offline token authentication in the environment before --> <!--test suite="Wikipedia.testsuite" project="OutOfWsp" workspace="C:/Runtimes/runtime-RptMvn" publish="https://<Server>#project.name=<ProjectToPublish>" publish_for="ALL"/--><!-- When the project name exists in two different team spaces, the conflict can be solved be adding teamspace.alias or teamspace.name as shown below --><!--test suite="Wikipedia.testsuite" project="OutOfWsp" workspace="C:/Runtimes/runtime-RptMvn" publish="https://<Server>#project.name=<ProjectToPublish>&amp;teamspace.alias=<TeamSpaceAlias>" publish_for="ALL"/--><!--test suite="Wikipedia.testsuite" project="OutOfWsp" workspace="C:/Runtimes/runtime-RptMvn" publish="https://<Server>#project.name=<ProjectToPublish>&amp;teamspace.name=<TeamSpaceName>" publish_for="ALL"/--><!--test suite="testSources/Test1.testsuite"/-->
                                        
  • 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.

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/IBM/IBMIMShared/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