jeudi 19 février 2015

Programmatically getting error messages/stack trace from Coded UI/unit tests

I'm writing a custom logger for a Coded UI project (though it would probably work for a unit test project as well). In the FinishTestLog() method of my Logger class, I am able to access the TestContext (using a reference provided elsewhere and stored in a private field) and get the CurrentTestOutcome, which is written to the log:



public static void FinishTestLog()


{ ...



String message;
if (_testContext != null)
{
message = String.Format("Ended execution of test case with outcome: {0}",
_testContext.CurrentTestOutcome.ToString());
}
else
{
message = "Ended execution of test case";
}

...


}


Sometimes tests fail, in which case the Test Explorer will show the error message and stack trace, which are written to the TRX file (if that is configured). It would be nice to be able to grab the error message and stack trace in the same manner as TestContext.CurrentTestOutcome, and not with wrapping every test method in a try/catch block. Is this info hidden somewhere in TestContext or another object?


Aucun commentaire:

Enregistrer un commentaire