Testing application logic with the automation framework
While developing a Digital Service application, you may want to know how your application logic works. You can test the working of your application logic, by creating tests for your application. To create tests for your application, BMC Helix Platform provides an automation framework.
The automation framework facilitates you to create the tests, run the tests, and view the test results. You can create test cases to test your application logic such as business rules or process.
The following image shows the stages involved in the process of using the automation framework to create tests:
Before you begin
- To install the automation framework
- To access the automation Java project
- To initially configure the automation Java project
To install the automation framework
BMC Helix Platform SDK consists of the automation framework JAR file that you can use to create automated tests for your applications. When you install BMC Helix Platform SDK, the automation framework is installed automatically and added to local the Maven repository. When you create an application using the Maven archetype and BMC Helix Platform SDK, a Java project named automation is included in your application. This Maven project contains Java automated test layout that you can modify to create tests.
To install the automation project in your existing applications or smart libraries, see Upgrading-BMC-Helix-Platform-SDK-to-20-02-01
To access the automation Java project
The source code for the automation project is located at /automation/src/test/ folder. You can access the project by using Eclipse.
- In Eclipse, navigate to File > Import.
- Select Maven > Existing Maven Projects and click Next.
- Click Browse and select your project main folder and import the automation project, and click OK.
To initially configure the automation Java project
The properties.config file in the automation folder contains the information to run your tests. Before running your first test, you must provide the following information in the properties.config file.
Modify the name parameter and set it to your developer instance.
#ServerInfoList
#primaryServer
name=developerxxxx.innovate.bmc.com
rpc=0
tcp=0
dbadmin=
dbpassword=
jettyPort=0
protocol=https
overlayOption=
#End primaryServerModify the developer account credentials and set the username and password to the credentials that you use to access your Amazon instance environment.
#userInfo
username=developer
password=developer
auth=
locale=en_US
#Run the following script to check if the use cases that you defined are covered in your process, that is, to check for the process coverage. The processes that are in the list of bundles defined in the bundles property are analyzed and exported.
bundles=com.example.taskmanager-lib
ignoreProcessCoverage=falseBy default:
- The bundles is set to your current application or smart library. To add several bundles, use a comma (,) as a separator.
- The process coverage is executed at the end of all the use cases as the ignoreProcessCoverage property is set to false.
Creating, running, and bundling test cases
- To create a class from a record definition
- To create automation tests
- To run automation tests from the command line
- To run automation tests from Eclipse
- To review the automation test results
- To review the process coverage test results
- To bundle the automation test cases with application
To create a class from a record definition
In the Task Manager automation example project, the Task record definition exists and can be manipulated as a class, extending the BaseRecordInstancebase class. This class bundles the get method and set method to access the fields as well as enumerated types to modify the status values as shown in the following image:
To create this Java class through the Automation Framework utility, perform the following steps:
- Open Windows command line and navigate to the application or library project available in /projects/<projectName>/ folder.
- Run the command mvn clean install in your project to generate all necessary libraries. Alternatively, you can run the command mvn -Dit.test=* verify from your project automation folder, such as /projects/<projectName>/automation/ folder.
- Open a Windows command line in the /projects/<projectName>/automation/target/ target folder of the automation project.
Run the following command to generate a class for a record definition.
java -cp <class path> com.bmc.rx.test.framework.util.CreateRecordDefinitionSupportClass "developerxxxx.innovate.bmc.com" "https" "<Jetty path>" "<user name>" "<password>" "<bundle name>" "<record definition>" "<package name>" "<export path>"For example:
java -cp com.example.taskmanager-lib-1.0-SNAPSHOT-automation-tests.jar;lib/*;%RX_SDK_HOME%/lib/*com.bmc.rx.test.framework.util.CreateRecordDefinitionSupportClass "developerxxxx.innovate.bmc.com" "https" "0" "developer" "password" "com.example.taskmanager-lib" "com.example.taskmanager-lib:dummy actions" "com.example.automation.test" "C:\\temp\\test\\"This command includes the following parameters:
Parameter
Description
com.example.taskmanager-lib-1.0-SNAPSHOT-automation-tests.jar;lib/*;%RX_SDK_HOME%/lib/
The class path must contain the following folder paths:
- Name of the JAR file in the automation project that contains the class required to create a Java class, such as com.example.taskmanager-lib-1.0-SNAPSHOT-automation-tests.jar
- Name of the /lib folder in the /target folder, such as lib/
- Name of the SDK library folder, such as %RX_SDK_HOME%/lib/
developerxxxx.innovate.bmc.com
Server host
https
Protocol to access your BMC Helix Platform server
0
Jetty port of your BMC Helix Platform server. Enter the Jetty port value as 0.
developer
User name to connect to the BMC Helix Platform server.
Important: Ensure you use the tenant user account, instead of the developer account, to test the runtime behaviour of applications.
password
Password to connect to the BMC Helix Platform server.
com.example.taskmanager-lib
Bundle name where your record definition is located
com.example.taskmanager-lib:dummy actions
Record definition (with the bundle name) that you want to convert to a Java class
com.example.automation.test
Package name that is used in the Java class
c:\temp\test\” is escaped so “c:\\temp\\test\\
Path to the folder where you want to place the Java class file, such as C:\\temp\\test\\
Enter the export path with two double slashes ("\\") because one slash is used as an escape character.
The Java file is available in the specified folder location, as shown in the following image:
To create automation tests
The automation project consists of the following folders:
main | This folder contains the MainAutomationClass.java file that you can use to execute all the test scripts in the automation project. |
sample | This folder contains AutomationSuite.java file that you can use as a master test script where you can define all your test cases. The AutomationSuite.java file also contains sample test code. This folder also contains the steps folder that consists of the following jGiven class templates:
|
You can extend the BaseTest class to create your test cases. For information about the methods available in the automation framework, see Automation-framework-methods.
To run automation tests from the command line
You can verify all the test classes or verify a specific test class.
- In a command prompt, navigate to to the automation folder.
Run the test cases by issuing one of the followings commands:
To verify
Command
All test classes
mvn -Dit.test=* verifyFor example,
A specific test case
mvn -Dit.test=className#methodName verifyFor example, mvn -Dit.test=TaskManager#VerifyTaskManagerCanCreateTaskAndAssociateWithGroup verify
To run automation tests from Eclipse
The automation framework uses jGiven and testNG framework to allow you to create tests cases in Java. For more information, see jGiven and TestNG.
Install TestNG Eclipse plugin.
- In Eclipse, test all the methods and classes.
To test a method, select the method and debug it.
- To test a class, run the complete class.
- View the test results in the Results of running class tab.
If you encounter the following error:
"org.osgi.framework.BundleReference"'s signer information does not match signer information of other classes in the same package site:icedtea.classpath.org
To resolve this error, in /automation/pom.xml file, delete the following code:<dependency>
<groupId>org.eclipse</groupId>
<artifactId>osgi</artifactId>
<version>${equinox.framework.version}</version>
<scope>provided</scope>
</dependency>- When you run testNG unit tests from Eclipse, you may receive an error that the class you are testing is not found. For example, Class com.example.automation.AutomationSuite is not in the classpath.
To resolve this error, clean your automation project (Project > Clean).
To review the automation test results
When you run a test, a test report is created in the /automation/target/jgiven-reports/html/ folder. The following image illustrates a sample test report:
To review the process coverage test results
After all the tests are run, a process coverage report is generated in HTML format as well as JSON format. You can access the report, which is located in this folder /automation/AutoLog/. The following image illustrates a sample test result:
A JSON file is created for every class, and contains statistics about the process and the activities that are executed, as shown in the following image:
The graphical process coverage files are available in the following folders:
Each folder contains a HTML file and a Javascript file. To see the process coverage, you must open the file index.html in Mozilla Firefox or Google Chrome browsers:
The HTML file contains all processes listed in bundles property from the properties.config file. Select a process to see the process coverage. Activities highlighted in green denote that the activity is covered. Activities highlighted in red denote that the activity was not reached or completed.
See the following image for more information:
To bundle the automation test cases with application
After you create your tests, you can bundle them with your application by using the following command in your project folder:
The ZIP bundle generated contains a JAR file that contains the tests, alongside your application or library.
Automation framework example
Example test cases are provided in the BMC Helix Platform SDK sample application, the Task Manager. See Example-of-using-automation-framework.
Related topics