One of the most critical phases of any development project is testing, to ensure that the implemented features work as expected. Automation of the testing process enables repeated executions of the test cases leading to more accuracy and time-saving. In webMethods product suite, the automated unit testing capability is provided as a Unit testing framework (earlier known as wMTestSuite). This article explains about using the Unit testing framework in a headless mode.
Note : This article does not cover the basics of creating / executing the test suite, it is rather focused on using headless testing using the Test Suite Executor feature. It is expected that the reader has knowledge of creating and executing test cases using Unit testing framework tool.
In general, Headless testing is a mode of running the tests without the head, which means there is no specific UI, or any GUI used. This becomes extremely useful when running any automated tests in a CI / CD implementation, where the primary focus may not be on visualizing the test executions on a GUI. The tests can be simply run in the background.
With this approach, the test execution becomes very lightweight utilizing less system resource as we can get rid of the overhead involving the UI to render the test results or any other processes involved to display the test results.
In webMethods, the headless tests can be invoked using the Test Suite Executor features accessible through the designer. It provides default Ant script and easily modifiable property files to implement headless test invocation setup.
Perform the following steps to create a sample test suite executor using the default files.
- Select File>New> Test Suite Executor in Unit Test Framework Perspective of SoftwareAG Designer.
- On the Test Suite Executor Project screen , enter the project name, folder path that contains the test suite setup files, and the file system. You can choose to use the default values.
- Click Finish .
Note: Before creating the test suite executor project, the test suites project should already be available.
The project contains default Ant build targets and properties to drive the tests. Below is a sample test executor project and its project structure,
Configuring test suite executor
Using Designer, you can configure the Test Suite executor after you have successfully created the projects. Perform the following steps to configure a sample test suite using the default files.
- To initiate the tests, use the ant build file, run-composite-runner.xml and ant target, composite-runner-all-tests
- Modify the properties file, run-test-suites.properties to specify project locations and setting up target Integration Server definition
- Specify appropriate values for each property in the run-test-suites.properties file to generate the results in the provided location as HTML files.
Note : Use readme.md for the details of each field defined in property file. To run the headless testing set webMethods.test.setup.profile.mode =NONE
Executing the project
- You can create a run configuration, Navigate > ‘External Tools configuration ‘
- Create a new Ant configuration ,
- Give a configuration name and select ‘run-composite-runner.xml’ file from the workspace.
- Click on run.
Viewing the resultsFrom the designer, In the project folder, right-click on the ‘ **index.html** ’ and open with any often provided options.
Note: You can also use Nodejs, tomcat, etc. to view the report locally. In Realtime scenario, this execution would be done by Jenkins and Jenkins HTML publisher plugin to view the report from Jenkins Server.
Another important aspect of any testing activity is the test coverage which plays a crucial role to ensure that every part of the code is tested as part of the test cases designed. Unit Test Framework allows you to record and analyze which flow steps and map actions of your flow service(s) are executed during a test launch. It helps to identify untested steps and improve the corresponding tests.
Before running the test coverage analysis, ensure that you activate the wM Code Coverage Agent. To activate the wM Code Coverage Agent, perform one of the following steps:
- On the Package Navigator right-click the default Integration Server instance and select wM Code Coverage Agent > Activate
- In Designer, navigate to Window > Preferences > Software AG > Integration Server and
- select the default server.
- Click wM Code Coverage Agent.
- On the wM Code Coverage Agent Settings dialog, select Activate .
Set the property webMethods.test.setup.profile.mode =COVERAGE in the property file and follow the same execution steps as mentioned in the earlier section
After you run the test, webMethods Code Coverage view displays a detailed coverage report of
the test session. The tested flow steps and map actions or Services appear in green and the untested flow steps and map actions appear in red.
You can view the code coverage report locally through NodeJs or Tomcat by just copying the ‘wmcodecoverage’ folder that contains all the report resources to the specific location of these servers.
You can use the Jenkins HTML publisher plugin to publish the code coverage reports if the execution is done by Jenkins.
• Full Packages View - Represent elements under the corresponding Packages and Service namespace. This View provides a detailed coverage analysis of the flow steps and map actions of all the individual service(s) under test in the test suite.
• Execution Model View - Represent elements based on invocation hierarchy. This View provides individual test coverage analysis of the flow steps and map actions of the individual service(s) involved in the test case.
• Service Level View - Represent only Invoked Services as elements under corresponding Packages. This view provides the coverage analysis of only the services invoked during the test case or test suite execution. This would be primarily be interested to developers.
For a quick start, you can use the inbuilt sample provided to create the test suite executor as mentioned in below steps,
- Select File > New > Test Suite Example
- Click on Next, On the Test Suite Executor Project screen, enter the project name, chose the default location to the Integration server package location
- Click Finish. The below project is created in the workspace with the necessary build path automatically configured.
This project already contains a few sample services and its corresponding test cases in the same project. In the actual project use-cases, the core services and the test suite projects will be maintained separately.
- Create the Test suite executor project and configure below properties,
- Right-click on the ant build file ‘run-composite—runner.xml’ > Run As > External tool configuration and create an Ant configuration.
- Click Run, After the execution completes the reports will be generated in the respective folders based on the chosen profile mode,
project/test/reports/html > If executed with no coverage mode (webMethods.test.setup.profile.mode =NONE)
project/test/reports/wmcodecoverage > If executed in coverage mode (webMethods.test.setup.profile.mode =COVERAGE)