This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Unit Testing

Unit testing is the testing of the smallest piece of code that can be tested in isolation. With regard to object-oriented programming, tests a class or methods behaviour, will make sure the functionality of the method is working as you expected by validating the output against the inputs.

A good unit test is:

  • Able to be fully automated.

  • Has full control over all the pieces running (uses mocks or stubs to achieve this isolation when needed).

  • Can be run in any order if part of many other tests.

  • Runs in memory (no DB or File access, for example).

  • Consistently returns the same result (you always run the same test, so there are no random numbers, for example, save those for integration or range tests).

  • Runs fast.

  • Tests a single logical concept in the system.

  • Readable.

  • Maintainable.

  • Trustworthy (when you see its result, you don’t need to debug the code to be sure).

Any test that does not live up to all these is an integration test and is put under the integration test module.

WSO2 Test Automation Framework does not support unit testing. TestNG is the recommended unit testing framework for the WSO2 developer community. It might not be possible to have the required environment or run time at the time unit test execution, so the developer can use the mock service frameworks such as easymock, mockito, etc to simulate environments.

Below is the dependency for TestNG.

<dependency>
           <groupId>org.testng</groupId>
           <artifactId>testng</artifactId>
           <version>6.1.1</version>
</dependency>

Unit test coverage

EclEmma is the recommended code coverage tool for unit testing. For more information about EclEmma integration with build system see EclEmma Based Unit Test Coverage Generation .