views:

68

answers:

2

I'm starting a new WPF/Silverlight custom control project and wanted to do unit testing on this one. However I'm a little confused about how to approach this.

This control would be based on the same codebase for both WPF and Silverlight with minor forking using #ifs and partial classes to tame the differences. I guess I could write unit tests for WPF part with NUnit, MSTest, xUnit, etc. and for the Silverlight part with Silverlight Unit Test Framework but this doesn't sound very elegant to me. I'd have to either ignore testing identical code on one of the platforms and test only differing parts (which is not very trustworthy) or rewrite tests for 2 frameworks (which is annoying). Is this the right way to go?

I'm wondering if there's some guidance, articles, tutorials out there on how to approach this task. Any pointers?

A: 

I am hardly an expert in WPF and Silverlight, but wouldn't it be possible to write the tests using the same techniques as the production code (#ifs and partial classes as you said)?

Grzenio
I guess the problem is in test runners. They run on full .NET and wouldn't normally run code compiled for Silvelright IMHO.
Alan Mendelevich
I was thinking that you should be running these test on the normal runner (the version compiled for .Net) and on the Silverlight (version for SL). I agree that it is a pain to run almost the same tests twice, but on the other hand how can you know if all the #ifs and comilations scripts were correct?
Grzenio
Yes, but as far as I understand most of the unit testing frameworks themselves are compiled against full .NET and won't run in Silverlight runner. I might be missing something or completely wrong but I see it this way.
Alan Mendelevich
A: 

I tried to use xUnit first but it was kind of complicated to make same tests work in xUnit and SLUT (different attributes, syntax, etc.)

Then I did some basic experimenting with MSTest and from very simple test it looks like you can successfully use MSTest for the WPF part and same code with some #ifs, etc. and SLUT for the Silverlight part. So I'll try to go this route and see how it works in real-world situations.

Alan Mendelevich