Continuous Delivery II: Smoketests in Ruby and Rails
This is part II in a blog mini series on building a build pipeline with Jenkins. The other parts, part I and part III could be worth a read too.
This part is about a implementing built-in smoke tests in a rails application. This Is by no means new, but I added a little something at the end which I thought was quite nifty.
Class definition
I created a small class to hold the actual smoke tests (pardon my ruby, I’m learning):
These are called from the SmoketestController. I chose to just put all (well all two) smoke tests in the controller, but they could easily be distributed and put wherever you want. The controller methods looks like this:
The “test” one is just for making it more than one, and the mongoDB test tries to do a query and gives it and ok status if that works, and a fail with stack trace if somethings amiss. In a bigger application with more external systems, the number of smoke tests would go up. Running this, gives this nice web page for visual inspection:
(The layout is a bit wide since I wrapped in the standard layout for the app.)
The Junit output
I wanted the jenkins build job to track these smoke tests, which are being run as a build step after deployment. The easiest way to do this I figured was to make it spit out Junit XML format and let Jenkins chew on that. So a created an XML template like so:
And when fetching the url http://server/smoketest.xml you get the following output:
(It handles failures too).
The following small shell script is used to check the status:
The shell scripts stores the file which is then read by Jenkins. Works like a charm!
Stay tuned for the third article on build pipelines where I explore some future possibilities when using a build pipeline.
blog comments powered by Disqus