Lighthouse – Silverlight Unit Test Runner Project released
Unit Testing in Silverlight? But you need Web Browser to do that!
No you do not! Ok maybe you do. But not in a direct way. I will clarify that later. Lets first go back in time to the root of the story:
Since the initial release of Silverlight i was really annoyed by the fact that Unit Testing had very slim support.
Even later when Silverlight Unit Testing Framework was introduced by Microsoft things became little better but still it was far from good.
You could create Unit Tests, but you had to start your Visual Studio in order to run them – eventually looking at the results of tests in your favorite Web Browser.
That ruled out one of the most important facets of Test Driven Development – running your Unit Test on Continuous Integration server, so that you can easily see when any of your Unit Tests are broken – in other words treating your Unit Tests equally as all your code, like you should.
Not to mention that there was no way to run Unit Tests from Reshaper! (oh boy don’t even let me get started on that one).
Can feeling of anger be a motivation for good deeds?
Very likely. I started by investigating what open source projects were available to fill these Silverlight TDD gaps.
And i did found few of them. But they were either too complex or simply did not work properly and failed to run tests from one reason or the other.
This is how i decided to create project Lighthouse – probably in same way how many other open source projects are born: to scratch an itch of single developer, for the benefit of the community
What is it for? What’s the Roadmap?
Lighthouse is envisioned as project that will host multiple tools that will allow Silverlight developers to do Test Driven Development much easier then before.
First tool in this project Silverlight Command Line Unit Test Runner has just been released on Codeplex website.
Lighthouse Command Line Unit Test Runner is console application that runs given Silverlight Unit Testing Framework Unit Tests and collects their results and saves them in known NUnit XML Unit Tests results file format on your hard-drive.
What can i expect?
The rule of the thumb goes like this:
YOUR SILVERLIGHT UNIT TESTS SHOULD BEHAVE EXACTLY THE SAME WHEN YOU RUN THEM WITH LIGHTHOUSE AS IF YOU ARE RUNNING THEM FROM VISUAL STUDIO OR WEB BROWSER.
In other words: If they failed in browser, they will fail when you run them via Lighthouse in completely same way (same timing, same exception etc) – and vice versa.
You can use Lighthouse to run tests in XAP packaged application or you can use it to run tests directly specifying your Silverlight DLL’s – it is very flexible.
Currently Lighthouse saves results in NUnit XML Unit Tests results file format so that means you can use it to run your Unit Tests in ANY Continuous Integration server that supports this format – CCNet, Team City you name it.
In future we will maybe add more output XML formats, but for start this should suffice.
Lighthouse Silverlight Command Line Unit Tests runner supports variety of command line switches so you can tweak it to work how you need it.
You can specify Tag Filter to run only certain test cases.
You can specify timeouts, output log file, output directory etc.
Make sure you visit the Lighthouse Command Line Test Runner Documentation page to get familiar with all the options.
In the future we are planning to develop Resharper plugin to run Silverlight Unit Tests, but you will here more on that when its ready.
And how does all this work?
Its much simpler to explain then it was to make it work:
In its essence, Lighthouse analyzes your XAP/Assemblies and modifies them in a way so that it can control the Unit Test execution. It then fires up a web browser instance in the background and start this modified Silverlight application and collects the results of all Unit Tests. Results are saved in XML file and everyone go home and live happily ever after.
For the end check out this short video where Lighthouse Command Line Runner executes Silverlight Unit Tests from Sterling project: