views:

504

answers:

7

I have plenty of experience with NUnit and MBUnit, but I'm new to .NET Compact Framework development and I'd like to get off on the right foot.

Is there a prevailing unit testing framework for the .NET Compact Framework, and if so, what is it?

+1  A: 

What's wrong with just using NUnit?

The unit tests don't need to run on the target device so I see no reason why you can't go with a normal unit testing framework.

Edit: Apparently this won't work, so ignore this solution. Please do not upmod.

Simon Johnson
Even if you do want to run unit tests on your device (for CF-specific functionality), it shouldn't be all that hard to get NUnit up and running on that environment.
Mark Bessey
@Simon: I disagree. In many cases the code certainly *does* need to run on the target device.@ Mark: It's easy to say that it shouldn't be hard. Reality says otherwise. It's not at all simple to get it working and it's fragile once it is.
ctacke
+1  A: 

@Simon: Modules compiled for CF.NET don't run on the desktop h/w, and therefore cannot be tested with NUnit.

Eric Farr
I was not aware of this. Can the people who awarded me rep remove it please?
Simon Johnson
Not 100% true. CF assemblies are retargetable, so if they're not using CE-specific calls, then they will work. Getting the test framework to load the CF code and not attempt to deploy it is the hard part.
ctacke
ctacke, I assume by "retargetable" you mean that they can be built as standard framework assemblies. I've considered that option, but it adds complexity to the build and we wouldn't be testing the code as it gets built for production.
Eric Farr
I now see what ctacke means by "CF assemblies are retargetable." It means that they will actually attempt to run on the desktop. See this article for details and options: http://msdn.microsoft.com/en-us/magazine/cc163387.aspx
Eric Farr
+2  A: 

Check out NUnitLite: http://www.codeplex.com/Wiki/View.aspx?ProjectName=NUnitLite

Matt Lacey
+1  A: 

We use MSTest under TFS (2008). The great advantage is that it runs the tests on an actual device (we run both against emulators and physical devices) and the testing is driven from the server, not the device. This means you don't have to select tests to run, etc. from a device UI (a la CFNUnitBridge), which is painfully awkward and not conducive to continuous integration.

MSTest is not a cure-all, however. It has some serious drawbacks (like debugging tests is really painful and test startup is slow), but it's better than anything else we've tried. The hope is that as MS moves forward, usability will improve and we can keep moving forward with the test framework we have.

Using anything else we find to be too risky, as many frameworks and libraries for devices tend to wither and die without some major sponsor. NUnitLite for example only has had 477 downloads and very little code churn or activity in a two-year life as of this post - that doesn't inspire any confidence that it will grow in features.

ctacke
Thanks -- I have heard some good things about the testing story in VS 2010, so I think your hope is likely to be rewarded.
Hugh
A: 

For more on NUnitLite vs compiling to a desktop version, check out this question and responses... http://stackoverflow.com/questions/14497/has-anyone-used-nunitlite-with-any-success

Eric Farr
+1  A: 

You have probably figured this out already, but with Visual Studio 2008 Professional, the "best" way is to use MSTest (I'm an NUnit guy through and through, but this is it).

Right-click on a method or class and select "Create Unit Test". That will guide you through creating the test project with all of the dependencies you need to get started.

Key point, this will run the tests on the device -- which is what you want to happen, then report the results back to you in the MSTest runner.

There are still testing issues though. I can't find any mocking framework that works with .net cf. But it is a start.

Chris Brandsma
A: 

For an embedded project running on Portable.NET, we ended up writing our own minimal version of NUnit, since we couldn't get the NUnit code to compile and run on that runtime. It wasn't really all that hard to do, actually.

Mark Bessey