Sunday, December 24, 2017

In-container unit tests (Docker TestNG integration)


With the advent of containerization of applications and the proliferation of micro-services, there arise a need to test containers similar to the way jar’s(java libraries) are tested using unit testing mechanisms. The example below demonstrates one such method that unitizes an environmental variable to trigger a TestNG test suite from outside a container. 

1.  Put in the test trigger code in your applications entry point as shown below,




2. Create a container consisting your application jar file(s), make sure all dependencies are available inside the container. In the example project the testng.xml file and a jar consisting of the application and its dependencies are copied into the container.



3.  Run the container passing in the environmental variable as show below,




Find the example code base here[1]. Note that the container is made problematically using the docker main plugin. 

No comments:

Post a Comment

What's in my Bag? EDC of a Tester