When I joined to Microsoft Patterns & Practices Mobile Client Software Factory team a couple of years ago, I discovered test-driven development as a reality, but the first big issue we had to face then, was the lack of unit testing support for the .Net Compact Framework.
Having so many testing frameworks for the full framework, the .Net CF was nobody's land regarding unit testing. Not even Visual Studio 2005, which includes on its Team Suite edition a nicely integrated Unit Testing framework provides support for .Net CF Unit Testing. There was only one option: build our own Unit Testing framework (or at least our test runner), and that was what we called the p&p Compact Framework Test Runner, which is part of the Mobile Client Software Factory.
It was just enough effort to make things work. There was a big wish list for cool features that never were done like IDE integration. I want to mention also another old project with the same mission, the CFNUnitBridge by Trey.
Now Visual Studio 2008 (formerly Orcas) has arrived, and it includes support for .Net CF Unit Testing which very nice IDE-integration, with the same approach of the full framework unit testing. Such a good news!
Wanna try it?
Let's do a remake of a very interesting Daniel Moth's post from a couple of years ago:
1) Let's create a new Smart Device Class Library for .Net CF 3.5 on Visual Studio 2008
2) Add a new class to the project with the following content:
public class Class1
public Int32 GetBuildVersionPart()
3) Right Click on the method and choose "Create Unit Tests..."
And select only the GetBuildVersionPart() method
Enter the Test Project name
It will create a new test project, unit testing class and the following unit test method:
///A test for GetBuildVersionPart
public void GetBuildVersionPartTest()
Class1 target = new Class1(); // TODO: Initialize to an appropriate value
int expected = 0; // TODO: Initialize to an appropriate value
actual = target.GetBuildVersionPart();
Assert.Inconclusive("Verify the correctness of this test method.");
4) Replace expected = 0 with expected = 50727 which is the build number for the full framework 3.5, and comment out the Assert.Inconclusive line (or delete it).
5) Run the GetBuildVersionPartTest from the Test View window:
It will build the projects, launch the emulator and run the tests on the emulator. After some seconds, the result will be:
This time the test has failed, the expected value was 50727, the build number for the full framework, but the actual value was 7283, the build number for the compact framework.
This time the Unit Test has run on the emulator! It really was a .Net CF Unit Test :)