views:

302

answers:

1

Hi,

I've got an ASP.NET MVC 2 Web app in VS 2010 and decided to try using MS unit testing stuff. What do you know, on the first test I created it gives me grief and refuses to elaborate.

I have created a single test class and a single test method. I am using Moq to create a HttpContext (including Request, Response, Session, QueryString, Form and Cookies). The method is testing an action on one of my controllers and an exception is occurring in that action when it use MVCs model binding capabilities. However that is not the problem.

When I run the test in VS it simply says: "Test Method [myTestMethodNameHere] threw exception: ..."! So it doesn't give me any idea what the exception is it literally says ... at the end, like a cliffhanger on TV - "... find out in VS 2011, coming soon" 8(.

Debugging the test doesn't help as it's occuring on the UpdateModel(T) line that I'm calling. I am using my own custom binder class but it doesn't get to the breakpoint on the first line of code in that so the exception must be happening in the MVC framework.

I guess this is all a long winded way of asking is there some configuration or code that needs to be written to get the MS unit testing framework to show me the exception in the test results window, is it me or does it sound like an MS issue that others have had?

Any help much appreciated, Peter

+2  A: 

Right click the failed test in the Test Results pane, and click View Test Result Details. You'll be given a document that specifies the exception, its message and stack trace.

Since you're using Moq, I'm guessing the type will be MoqVerificationException - MSTest unfortunately doesn't pick it up the same way it picks up AssertFailedExceptions, so no nice error messages there...

Tomas Lycken
LOL - That was it. It showed the exact exception (Null reference).I'd written an NUnit test and found the exception before seeing this, ha. Hmmm VS 2010 display method for issue is just not very nice. Double clicking in the results pane takes you to a line of code rather than to view the details of failure.
Peter
If you're testing with NUnit, I'd really recommend using another test runner than MSTest. After finally figuring out how to use the TestDriven.Net (guess their website? ;) runner integrated into visual studio (it was really easy - I'm the fool here...) I decided only yesterday to migrate my tests to NUnit and use that instead. You'll get the nice error messages you get from MSTest for AssertFailedException for loads of other types too - among them, the NUnit AssertionException.
Tomas Lycken
I was trying to use the MSTests when I posted the error. But I added an NUnit test and then fired up the NUnit GUI app separately and ran it on my Tests.DLL to get the exception.I saw when creating my projects I could choose another test framework but I was aiming to try MSTests so used the default. Now however I can't find where I would switch to using NUnit. Although I now I had the "doh!" moment pointed our by your first response it's not an issue more a nice to know.
Peter