This is part of my automated build series. The aim is to automate a lot of the Cordova Background Service plugin process.
In this blog I'll use the tools I created in the previous part to build a Jenkins job that tests the plugin.
In much the same way as I have a parameterized build job (see Part 2), I also want a parameterized test job. The test job will, for each version of the Background Service plugin, run through some tests (using Jasmine and the tools I build in the last post) and output files ready to be pushed up to Github.
I have a test project setup in my SVN. The test project is an Android/ Cordova project which is set up with the MyService I provide as a sample in Github.
Within the assets/www of the project I have a sub directory for each version which contains:
I also, have with the assets a Jasmine area which is configured to use my REST reporter as described last post and a version of the PluginSpecRunner.html which expects the following files:
As you will see later in job steps, for the version under test, I copy the version specific files into the src folder (renaming them).
The Cordova app is automatically set to run the PluginSpecRunner.html on start.
For this part, I'll be using the following tools:
I wanted to separate the testing logic out into this separate section. As mentioned I'm using the Jasmine BDD framework to test my JavaScript interface. Jasmine uses a "spec" definition. At a high level the test will:
Note: My current "spec" doesn't test all of the Plugin or Background Service functionality. I will expand this over time, but the above are the key areas that I want to focus on at this time.
Easiest way to explain what I'm doing is just document the code ... so here goes:
The Jenkins job will be parameterized to allow it to be called repeatedly for different versions.
As such the following variables will defined in the job:
To create the job;
[UPDATE]: Version 3 of Cordova needs Android OS 2.2 as a minimum. As such I have since changes the above Android OS version. I also tick the "Use emulator snapshots" as it speeds the whole process up.
Add a Windows Batch command to copy the relevant libaries into the source and set up the correct js file for Jasmine:
Add a Windows Powershell script to update the .classpath file with the relevant versions of the Cordova and BackgroundService libraries.
Add a Windows Powershell script to load in a Cordova version specific res\xml\config.xml. I've needed to do this because of the difference in structure used between 2.x.x and 3.x.x. I store the is res\xml\x.x.x\config.xml where x.x.x is the Cordova version number.
Add a Windows Batch command to prepare the project:
Invoke Ant to actually build the app
Add a Windows batch commend to run the app on the Android emulator
Add a Windows Powershell script to check that the app is running
Run the JasmineReceiver.exe created in the last post. Note that the Jenkins job will wait for the console application to complete before proceeding to the next step. The console application will close either when the timeout has exceeded or all of the test results have been received from the app running on the Android emulator.
Add a Windows batch command to close the app on the Android emulator
Add a Windows Powershell script to check that app has stopped
Finally a script to copy the relevant files for later use
And that's it. Should any of the steps fail (build, install, etc) then the whole job will fail.
There is quite a lot in the above, but hopefully it makes sense. If not please add a comment and I'll answer to the best of my abilities.
Next step, running the overall job (calling the build and test for each version).