-
Notifications
You must be signed in to change notification settings - Fork 80
UnitTesting
This document provides demo instructions for running Test Assertions in BusinessWorks 6.5 with the BusinessWorks Maven Plugin. The test assertions feature provides the capability to run unit tests within BusinessWorks 6.5. Unit tests focus on testing small “units” of work, which in BusinessWorks maps to individual sub-processes. Ideally this is done in a standalone manner, with no touchpoints with or dependencies on other components or interfaces. This is distinct from interface or system testing which would test the service/operation as a whole. Interface tests could be run using other tools such as SOAP UI.
By design, BusinessWorks test assertions don’t test the top-level process – they only test sub-processes. For example, if you had an EMS receiver as the start of a top-level process this would require an interface to EMS to run the tests which creates a dependency.
While test assertions have been available in previous versions of BusinessWorks, these instructions are specific to BW 6.5 which introduced the ability to run unit tests in isolation, i.e. just test individual sub-processes using Maven without having to start the whole service. BW 6.5 also introduces new capability around unit test reporting and test coverage reporting.
• BW 6.5.0 (with no HFs) – there is a known issue with BW 6.5.0 HF3 (and possibly HF1 and HF2). If HF3 is currently installed it is possible to temporarily move the contents of \bw\6.5\system\hotfix to another directory to run this demo
• Maven: https://maven.apache.org/download.cgi
• BusinessWorks Maven Plugin – follow instructions here: https://github.com/TIBCOSoftware/bw6-plugin-maven
• UnitTestDemo.zip downloaded in an accessible location
- Open Business Studio for BusinessWorks and create a new Workspace
- Go to File -> Import -> General -> Existing Studio Projects Into Workspace and hit Next:
- Select the “Select archive file” radio button and browse to the supplied UnitTestDemo.zip file then hit Finish:
- In the Project Explorer window drill down through the Processes in the demo project and open the UnitsService Process. This is the top level process which offers two REST calls to retrieve distance unit and temperature unit:
This section isn’t required to run the unit tests, but may be useful for understanding of the demo project.
- Test that the service runs through the Swagger tester. Go to Run -> Debug Configurations -> BusinessWorks Application -> BWApplication then hit Debug:
- In the Console window type: lrestdoc
- Copy the Discovery URL into a browser, click on Show/Hide next to the UnitsService and enter “NAM” in the region field then hit “Try it out”:
- You should get a response that looks something like the following:
- Change the value in Region to be “EMEA” and hit “Try it out” again.
- Back in Business Studio click on the red square above the Console tab to stop debugging, then click on the Design perspective in the top right-hand corner.
This section assumes you have already opened the demo project as described above.
- In Business Studio, right-click on the Tests folder for the demo project in Project Explorer and choose New -> Add Test File (note, in new projects you’ll either need to explicitly state that you want to create a Tests folder in the Create Project wizard or right-click on the project and choose New -> Tests Folder). Leave the Test folder as default and change the File name to GetDistanceUnit-NAM.bwt and hit Next:
- Add GetDistanceUnit.bwp to the process then hit Finish:
- Open GetDistanceUnit.bwp from Project Explorer, click within the boundaries of the distance.GetDistanceUnit process (green box in the screenshot) and select the Properties tab. As we’ve added this process to a Test File, the Tests tab should now appear – click on it. The Test file we just created will be selected in the Available Tests dropdown:
- Right-click on the Start activity and choose Add Test -> Add Input. In the Content field for “region” enter NAM (note no quotes around NAM):
Note : From BW 6.7.0 & Maven plugin 2.8.0 onwards, you can provide external XML file for Start activity mocking input.
Note : you don’t have to save the process after adding test inputs and assertions
- Right-click on the End activity and choose Add Test -> Add Input, then click on the Tests tab under Properties and expand AssertType+ and $End-input (i.e. both sides of the mapper):
6.Drag the “string|boolean|…” element from the right-hand side onto any element on the left hand side of the mapper underneath $End-input. It will bring up a wizard to choose the type. Choose string and hit Finish:
7.It should now show testInput and goldInput fields:
- Drag “unit” from the left-hand side onto testInput. This is the value that you are evaluating in the assertion. In the goldInput enter “miles”:
- Right-click on AssertType and choose Duplicate. Right-click on Primitive-Assertion and choose Expand All. Under the second AssertType element right-click on AssertType and choose Remove Mapping. Drag the “string | boolean…” field from the right-hand side to any element under $End-input on the left and choose “boolean” this time. Drag the “metric” element from the left onto the testInput field under Boolean and enter false() in the goldInput field:
- In a similar way to above, complete the mappings so that you also assert "subUnitType" and "numberOfSubUnits"
It should look like this:
- This has completed the assertions for the first unit test. Now, add another test file. Right-click on the Tests folder in Project Explorer and choose New -> “Add Test File”. Change the file name to be GetDistanceUnit-EMEA.bwt then hit Next:
- Select GetDistanceUnit.bwp and hit Finish:
- Open GetDistanceUnit.bwp from Project Explorer, click within the boundaries of the distance.GetDIstanceUnit process (green box in the screenshot) and select the Properties tab. Click on the Tests tab. The /demo/Tests/GetDistanceUnit-EMEA test file should be selected in the dropdown. If not, select it now:
- Right-click on the Start activity and go to Add Test -> Add Input. Ensure that the TestFile at the top of the tests file shows it is GetDistanceUnit-EMEA. If not, go back to the previous step and select it in the Test properties for the Process. In the region field, enter EMEA:
- Right-click on the End activity and choose Add Test -> Add Input. Ensure that the TestFile at the top is GetDistanceUnit-EMEA. If not, go back and select it in the Test properties for the Process. It should now look like this:
- Repeat the process that was followed above for GetDistanceUnit-NAM to set the assertions for GetDistanceUnit-EMEA with "unit","metric","subUnitType"and "numberOfSubUnits"
It should now look like the following:
1.In Business Studio, right-click on demo.application and choose Generate POM for Application. Set Tibco Home as the TIBCO Home for your BW installation with no trailing slash, e.g. C:\tibco\bw650 for Windows. Set BW Home as the relative path to the version-specific BW folder under TIBCO Home (with leading slash and no trailing slash), e.g. \bw\6.5 for Windows. Hit Finish:
2.This will now have converted the existing projects to Maven nature, added a new project called demo.application.parent and created pom.xml files in all projects:
3.Go to Run -> Debug Configurations, right-click on Maven Build and choose New. For the Base directory choose Browse Workspace and choose demo.application.parent. In goals enter “clean initialize site package”, then hit Debug:
4.The tests will now be executed and the output shown in the Console window. We should see that one of the Tests has succeeded and one has failed. This has also caused the build to fail:
5.Open GetDistanceUnit.bwp and select the Mapper activity, then the Properties tab and Input. It’s now obvious that there is a copy/paste error in the Otherwise clause for the unit element which incorrectly maps to “miles”:
6.Set the unit under Otherwise to be “kilometres”:
7.Save the Process
8.Go back to Run -> Debug Configurations, choose Maven Build -> New_configuration and hit Debug:
9.Again the tests will be run and this time both tests should complete successfully:
The ear file will now have successfully have been built and is located at \demo.application\target\demo.application_1.0.0.ear
1.Go to your command prompt/terminal of choice. Navigate to the location of your demo.application.parent project.
2.Run:
mvn clean initialize site package
This should produce the same results as running Debug from within Business Studio:
The “site” goal that we included in both the Maven debug configuration in Business Studio and on the command line produces unit test reports and test coverage reports. These test reports are located at \demo.application\target\site.
1.Open index.html using your browser of choice
2.Select Project Reports -> bwtest. This shows a summary of the tests that were run and whether they passed or failed:
3.From the same folder, open bwcoverage.html. This shows a summary of which processes and activities are covered by unit tests, for the entire project and as breakdown for each process:
Note that the top-level process isn’t included in this list as it can’t be unit tested. This could be used within CI tools such as Jenkins to ensure that a certain percentage of tests are covered in order to allow a build to proceed.
- Only sub-processes can be used for unit testing – top-level processes aren’t supported
- Only simple (primitive) assertions are currently supported
- BusinessWorks needs to be installed on the same server where the tests are to be run
- Mocking of outbound service calls, e.g. invoke REST API, DB calls, EMS queue sender, is not currently supported, but is planned for future releases
- Unit Tests can currently only be invoked via Maven
- Keep sub-processes small so that they perform distinct functions which can be individually unit tested
- Keep top-level processes thin so that they only perform transport-level logic. Mappings and transformation can then be performed in sub-processes which can be unit tested
- Keep one unit test (and one process) per test file and use a suitable naming standard so that it’s obvious what each file is used for.
- When specifying inputs to a start activity and adding assertions, make sure that the Test File is correct – it tends to revert to the last Test File that was added. Go to the Tests tab in the Process-level properties to change this
- This document uses assertions on the End activity, but they can be used on any activity that has an Output
- TIBCO Home and BW Home can be changed in the pom.xml file of the application, e.g. demo.application. If using the Maven editor in Business Studio the values are in the Properties section of the Overview:
- The following goals can be used with the BW Maven plug-in:
- clean – remove files generated by previous build
- initialize – initialize build state. Always include
- site – generate the project’s site documentation, including unit test reports and test coverage reports
- test – run unit tests
- package – Build the BW ear file. Note that this also runs test, so don’t specify test if you’re including package
- deploy – deploy to target environment
These goals are all part of the standard Maven Lifecycle. More information on the Maven lifecycle is available here: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html • Maven can be called from CI tools such as Jenkins
Getting started
- Steps to Mavenize BW Application
- Building applications for BWCE
- EAR deployment with Config File
- Shared Modules with Maven
- Add Process Diagram in EAR
- BW Design Utility Goals
- CI/CD using Jenkins
- Custom XPath Function
- Deploy Shared Module on Remote Repository
- TCI Deployment using Maven Plugin
Unit Testing
- Primitive Assertion
- Activity Assertion
- Activity Assertion with Gold Input File
- Mock Output
- Mock Fault
- Test Suite
- Plugin Properties
Help & Contribute