Friday 4 April 2014

Making Unit and Integration Tests coexist - Maven/TestNG

Recently I had to make unit and integration tests coexist in the same maven project (pom), up-till then integration tests resided in a separate project (nice and easy).  However ideally these should co-exists in same project to make versioning/branching possible.

This small post I will share the steps taken to make this possible.

Technologies used here are:

- Maven
- TestNG

Goals: 

- mvn test should only run unit tests
- mvn integration-test should only run integration tests so that they do not cause issues building the project and are not included in the maven lifecycle for mvn install

Steps:


  • Make 2 different testng.xml files called:
    • ITtestng.xml (for integration tests)
    • UTtestng.xml (for unit tests)
  • Include maven-failsafe-plugin in your pom.xml to run just the integration test cases. Please not maven-failsafe-plugin is designed to run integration tests while the Surefire plugins is desinged to run unit test more info on this can be found here.
  • That is it! 
    • Now your mvn test command will run only the unit tests. Also mvn install will not run integration tests and cause the build to fail
    • mvn integration-test will run both unit and integration tests.


No comments:

Post a Comment