.NET unit test runner outputting FaultException.Detail

Posted by Adam on Stack Overflow See other posts from Stack Overflow or by Adam
Published on 2011-01-11T21:15:09Z Indexed on 2011/01/12 6:53 UTC
Read the original article Hit count: 268

Filed under:
|
|
|
|

Hello,

I am running some unit tests on a WCF service. The service is configured to include exception details in the fault response (with the following in my service configuration file).

<serviceDebug includeExceptionDetailInFaults="true" />

If a test causes an unhandled exception on the server the fault is received by the client with a fully populated server stack trace. I can see this by calling the exception's ToString() method. The problem is that this doesn't seem to be output by any of the test runners that I have tried (xUnit, Gallio, MSTest). They appear to just output the Message and the StackTrace properties of the exception.

To illustrate what I mean, the following unit test run by MSTest would output three sections:

  • Error Message
  • Error Stack Trace
  • Standard Console Output (contains the information I would like, e.g. "Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: ..."

try
{
    service.CallMethodWhichCausesException();
}
catch (Exception ex)
{
    Console.WriteLine(ex); // this outputs the information I would like
    throw;
}

Having this information will make the initial phase of testing and deployment a lot less painful. I know I can just wrap each unit test in a generic exception handler and write the exception to the console and rethrow (as above) within all my unit tests but that seems a very long-winded way of achieving this (and would look pretty awful).

Does anyone know if there's any way to get this information included for free whenever an unhandled exception occurs? Is there a setting that I am missing? Is my service configuration lacking in proper fault handling? Perhaps I could write some kind of plug-in / adapter for some unit testing framework? Perhaps theres a different unit testing framework which I should be using instead!

My actual set-up is xUnit unit tests executed via Gallio for the development environment, but I do have a separate suite of "smoke tests" written which I would like to be able to have our engineers run via the xUnit GUI test runner (or Gallio or whatever) to simplify the final deployment.

Thanks.

Adam

© Stack Overflow or respective owner

Related posts about wcf

Related posts about unit-testing