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/.
Best Practices for Writing Integration Tests
Following are some useful best practices to follow when writing integration tests.
- Use the @AfterClass annotation to clean up any resources you put into servers after test execution.
- Use assert statements instead of sysouts while running tests.
- Use the @Description annotation to add a meaningful description to each test method.
- Include Javadocs at the top of the class, and make sure to included a description under the @Test annotation.
- Describe the scenario as a class comment.
- Follow coding conventions.
- If exceptions are expected, use the @ExpectedExceptions annotation.Â
- Throw all unexpected exceptions from the test methods so that these tests result in errors, not failures. Do not follow the Catch and Fail anti pattern. For more information, see the following resources:
http://testng.org/javadoc/org/testng/annotations/ExpectedExceptions.html
http://www.exubero.com/junit/antipatterns.html#Catching_Unexpected_Exceptions - All test method names should start with the prefix
test
, e.g.,testAddResorce
,testVerifyAvailabilty
, etc. - All test class names should end with the suffix
TestCase
, e.g.,ResourceManagementTestCase
- If you are writing a test case for a public JIRA, prefix the class name with the JIRA issue ID, e.g.,
Carbon1209TestCase
- Group test methods by product, e.g.,
wso2.greg
,wso2.esb
, etc. Don't create tests as private methods and call them inside tests. For example:
@Test(groups = {"wso2.as"}) public void testWebappExample() { testUserManagerAndAuthenticationDemo(); testRegistryUsageDemo(); testCarbonCachingDemo(); }
- Use testNg assert appropriately. Writing test cases without using assert will result in false positive test results.
- Use unique names for each resource in a product, such as governance resources. This will eliminate future conflicts if one test fails. For example:
String resourceName = ${ClassName}testSymlink;
- Use the testNg annotation @BeforeClass to initialize the environment and other instances. Use @AfterClass to clean up all resources used inside the test and make sure to revert the system to its initial state.
- When writing tests, consider the platform aspect and that the same test will be run on a clustered product platform or cloud platform.
Make sure to use proper environments for each test. You can use the custom testNg annotation @SetEnviroment to skip tests by environment. For example:
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.platform})
Don't use dependsOn and priority annotations together in same test class, as this will lead to testNG issues.
Avoid using the same test method name in different classes with the dependsOnMethod annotation, as this makes it hard to follow your code.
Priority annotation works fine from 1 - 10. If you are going to go beyond 10, use the testNG dependency model.
Â