2

I've got a few classes worth of Selenium tests set up and ready to run, however I'd like to log the test results to an external database (in addition to internal TFS status) for different analytic analysis. As part of this I'd like to store the exception as thrown by the test.

I've seen deployments elsewhere which made use of MSTest and still logged exceptions to an external database, but I can't seem to find the correct layer that exposes the thrown exceptions to where I can log them. TestContext doesn't contain them, there's no obvious way to invoke a test within a try/catch block and nothing relevant shows up in the [TestCleanup].

The closest answer I can find on StackOverflow would be this question from 2010 which doesn't seem to have a particularly conclusive answer. Ultimately non-C# programmers will be writing tests on top of my framework, I'd prefer to have them write as little cargo-cult-code as possible.

Is there a way to get the exceptions thrown from within a test running in MSTest? It obviously gets stored by the MSTest system, so it has to be caught somewhere.

Community
  • 1
  • 1
Cellivar
  • 568
  • 10
  • 27
  • The test runner for Visual Studio 2012 and up can receive a logger instance from the command line `/logger`, and you should be able to "roll your own". See: http://msdn.microsoft.com/en-us/library/jj155796.aspx and https://github.com/JakeGinnivan/VSTest.TeamCityLogger/tree/master/VSTest.TeamCityLogger – jessehouwing Jul 14 '14 at 11:55
  • @jessehouwing: you should add that as an answer, for posterity. – John Saunders Jul 14 '14 at 19:17
  • Is there a formal way to interact with that outside of a compiled binary? I'd rather refrain from further expanding the test suite. – Cellivar Jul 14 '14 at 21:56

1 Answers1

0

The test runner for Visual Studio 2012 and up can receive a logger instance from the command line /logger, and you should be able to "roll your own". An example logger can be found on GitHub. You can install the logger onto the machine executing the tests and then it doesn't require any code in your actual test projects.

You can also set the config to trx and parse the file, but you'll have much better access to the data in the Logger interfaces.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341