views:

163

answers:

5

Not something too large, yet no 2+2=4 type of examples either. Specifically it would be nice if it were WPF and MVVM. I'm confused on what to test for the view model.

How do you test what is in Lambda's? Do you? Do you make a function public just so you can test it. Or do you just test the final result?

+1  A: 

NerdDinner is a good, relatively simple ASP.NET MVC application that includes a full suite of unit tests.

Dave Swersky
Hmm ASP.Net MVC must be quite a bit different in testing than WPF MVVM. But that answered some questions.
nportelli
Actually I *think* NerdDinner uses some viewmodel-like projections so as far as the testing goes you should find some useful examples.
Dave Swersky
+1  A: 

I use the Nunit test suite with WPF/MVVM. Here is a decent tutorial to get you started.

When I write my unit tests, what I test for depends on what the object is doing. Most cases the Final Result is enough. I primarily test my public methods/attributes, to make sure based on known circumstances the outcome is what is expected. (Remember, with TDD, your suppose to write your tests before you write your code.)

CodeProject has several Nunit projects that you can download and step through, that's how I got started.

Test things like boundaries, success/failure, and equivalency. The more you practice, the more things you'll think of to test for, and the more comfortable you will get with it.

Update - More Complex Projects

If you want more advanced, here are some projects that include Mocks, which for me, was the hardest thing to grasp with Unit Testing.

jsmith
I asked for no 2 + 2 type of examples because they are just not "real world" enough. Or else my projects are way off base in regard to unit testing.
nportelli
@nportelli For me, the most "real world" examples for Unit Testing are the most simple examples. The concept itself is suppose to help you break things down in a more simple manner. Your most common tests will be extremely simple.
jsmith
True enough, how about a complex problem that is broken down into such simple bits? A calculator is just too simple.
nportelli
A: 

If you watch this awesome video by Jason Dolinger (I used to work with him, he knows his stuff!!) he touches on Unit Testing within a MVVM world. It's not extensive, but it should give you some idea.

http://www.lab49.com/files/videos/Jason%20Dolinger%20MVVM.wmv

BFree
+1  A: 

Roy Osherove did some interesting / cranky videos about test quality in well known open source code.

Mark Simpson
A: 

Check out Prism from Microsoft's Patterns & Practices Group, download here: http://compositewpf.codeplex.com/

Includes multiple example code solutions and extensive unit tests.

Mahol25