Thursday 3 December 2015

Bamboo and Python Unit Tests

Recently I have been moving to Bamboo and integrating all the sweet features that it has available. Using it has been a bit of mare to do some things - (Bamboo and Squish for GUI testing) I'll detail that in another post, and bamboo's design and use is completely different to Jenkins.

I think Bamboo's plan, task and job approach is very top down, as opposed to Jenkins which is quite bottom up.

However one of the easier things to get done was getting the build to fail on the output of units tests created using the standard library in python. Then getting the failures to appear once the build has been completed in the build results.

An example:

Create a new repository with a test folder with a test_test.py file containing the below


def test_failure():
    assert False
def test_pass():
    assert True

This created a very simple unit test case to check in bamboo. One pass and one fail. Simple right...

So create a new plan that has a single job with tasks to
a. clone the repository
b. run the tests, remembering to pipe the output into a junit xml output to the test report folder:

py.test --junitxml=test-reports\results.xml
exit 0

the exit 0 is important on windows because if you don't do this the bamboo job can fail from a failure to run the tests at this point and does not parse the results of the tests for display in the bamboo GUI. This is not what you want to occur because if the tests fail to run you still want the tests that you have run to give you information from the results screen.

Then use a junit parser task (built into bamboo from the word go) to process the results:




BAM (boo)
job done.

Unit test in bamboo, detecting a unit test fail and showing details about the test and number of builds it has been failing for. In all this is a really useful feature of bamboo that can be configured out of the box pretty much,

No comments:

Post a Comment