This is part of my automated build series. The aim is to automate a lot of the Cordova Background Service plugin process.
I'll need some custom tools and processes to test the library. In this post I'll blog the reason why and the tools to use.
To facilitate this I have created two components:
- A reporter for use with the Jasmine BDD framework. This reporter sends the results via REST to a receiver (Windows Console application).
- A receiver that has been written to be used with Jenkins CI to automate the testing of an Android application (although I'm sure it can be used for more). The receiver is used by Jenkins to wait for the Jasmine tests to be run. Jasmine, using the REST reporter, will send the results of each spec and suite to the receiver. The receiver will error (returns an error code to Jenkins) if any of the tests fail, none of the tests run or after a timeout period (5 minutes). Jenkins will then act of the result code.
At the time of writing all of the URL details are hard coded. I've provided notes below on what to watch for.
Words of wisdom: Because this uses hardcoded details - be mindful of IP/ computer name changes. I spend an hour debugging this only to finally realise that my laptop had picked up a new DHCP address.
- Jasmine BDD (https://github.com/pivotal/jasmine)
- Visual Studio 2012 Express for Windows Desktop (its free)
- Jasmine REST Reporter (https://github.com/Red-Folder/Jasmine-REST-Reporter/blob/master/jasmine_rest_reporter.js)
- Windows Application Console receiver - made up of:
How to use the tools
The Jasmine bit
The jasmine_rest_reporter.js is used within your Jasmine tests. Using the example project from Jasmine site (https://github.com/pivotal/jasmine/downloads);
1) Copy the jasmine_rest_reporter.js into your project
2) Copy the jQuery library into your project (I'm using jquery-1.10.2.min.js). The jasmine_rest_reporter.js uses jQuery for the AJAX functionality.
3) Amend the PluginSpecRunner.html to include script links to those two .js files
4) Amend the PluginSpecRunner.html to include the following lines just after the htmlReporter is added to the jasmineEnv:
var restReporter = new jasmine.RESTReporter();
NOTE: jasmine_rest_reporter.js is hard coded to a specific URL. This will need to amended for your environment.
The receiver bit
The receiver provides the REST service that the reporter communicates it's results to.
It's a fairly basic application - it will print to the console the details it receives from the reporter. It will also exit with an error code if any of the tests fail, none of the tests run or after a timeout period (5 minutes).
You can build the receiver using Visual Studio 2012 Express for Windows Desktop (or greater).
1) Create a new console application
2) Replace the Program.cs with copy from GitHub
3) Copy in the FormatterConfig.cs and LoggerController.cs from GitHub into the project
4) Use Nuget to add the following packages:
- Microsort ASP.NET Web API Self Host
This should give you a Console Application ready to use
NOTE: The Receiver is hard coded to a specific URL (see program.cs). This will need to be amended for your environment.
The permissions bit
Windows needs to be told that the Console Application is allowed to listen on the given port. To do this run the following command:
netsh http add urlacl url=http://+:8181/ user=machine\username
where machine\username is your user account.
NOTE: If you change the port that you run the Console Application on, then this will need to be reflected in the above command.
The above is all prep for the next Part of this series - that article will go through how to use the above in a practical situation.
Labels: Background Service, BDD, Continuous Integration, Cordova, Jasmine, Jenkins