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 will 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: ..."
public void Test()
{
try
{
service.CallMethodWhichCausesException();
}
catch (Exception ex)
{
Console.WriteLine(ex); // this outputs the information I would like
throw;
}
}
Edit: However, I would prefer that I was not forced to catch the exception in each test and write it to the console in order to ascertain the content within a FaultException
object's Detail
property.
For example,
public void Test()
{
service.CallMethodWhichCausesException();
}
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 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