Jun 202015
 

I have been using a library called libunittest for unit testing an open source project. A couple months ago I did a feature request for it, namely for an assertion for relative approximation. It’s an incredibly easy library to use and comes with a lot of documentation. Here is one of the examples which shows the “easy” way where you don’t have to register the test class:

After installing, link against it and compile, then execute:

This example and others are covered in the tutorial provided on the website: http://libunittest.sourceforge.net/tutorial.html

I personally like a different style that libunittest supports which is a bit more writing of code but I believe it’s a nice way of organizing a test suite:

For learning about the other types of assertions you can do, you may want to peruse the testing code:

http://sourceforge.net/p/libunittest/code/ci/master/tree/test/test_assertions.cpp

Happy testing!

Jan 242015
 

Selenium requires launching a browser on whatever machine is running the tests. Having a display connected to every machine you wish to run Selenium tests on is incredibly cumbersome. To get around this, you can do headless Selenium testing using a program called Xvfb which is a display server implementing the X11 display server protocol. I realize that there is a Xvfb plugin for Jenkins. However, I’ve experimented with it and found it wasn’t completely stable.

First we install Xvfb:

I made a previous post about installing a command line tool as a Linux service, so you could go that route. But if you’d prefer to just use it on the fly then you could do the following:

Add an init.d file to start Xvfb on a particular display variable, in this case 99:

Add the following to the xvfb file:

Then change the permissions on the script and see if it works!

Then in the Manage Jenkins menu, we add an environment variable DISPLAY with it’s value set to :99 in the Jenkins system configurations. I believe by default these variables are inherited by every Jenkins project unless you choose otherwise. If you wish, you can also add ‘/etc/init.d/xvfb start’ to /etc/rc.d/rc.local in order to have it start a server on DISPLAY=:99 every time the machine is rebooted.