Monday 12 December 2016

Test log lines

Some times the only thing we are interested in testing is weather a log line correctly gets logged. This is not the most optimal test but sometimes its required... in cases where log lines are getting monitored by a monitoring agent and we want to make sure correct format gets logged etc.

The trick is to mock the Log Appender and then capture the logs on that appender in a safe way. Once these log lines are captured you can verify them to your hearts content....

A fully working example of this is given at: https://github.com/njaiswal/logLineTester

Following snippet shows how to achieve this:

Thursday 11 February 2016

Run background server during integration tests

Most of the times during integration testing we have to run the built java code in server mode and run client junit/testng tests against the server. Mostly this has to be also done on the CI Jenkins server as well. Following post will go through some of the techniques to achieve the same.

Assuming the project is built in maven, run the integration test server (your application) in the pre-integration-test phase using maven-ant-run plugin.



Above maven plugin will run your main class in a forked jvm process in background and then you can run your junit/testNg integration tests against this server.



One of the issues that you will face is to stop the server once integration tests are complete.
For this you can create a method call to exit the test server if possible or exit the test server after a time interval. However this needs to be implemented server side. If you only run integration tests on Jenkins, Jenkins will make sure to kill all the pids that were created during a integration test run and keep integration test environment clean.

Happy testing...