Reputation: 418
We have a bunch of tests at my work that occasionally fail if the load on our CI server gets too high or an external service (GoogleDocs etc) API call times out. Is there a way that I could setup the TestCleanup code so that tests could be rerun and if they pass they don't show up as failures in the .trx files?
We are using VS2013/.Net 4.5 MSTest and the results are feeding into Jenkins ultimately. What I'd like to be able to do is detect that things are failing because of throttling or load and add delay code and retry again. Is this possible?
Upvotes: 2
Views: 796
Reputation: 1
This how you can extract failed cases names.
System.Xml.Linq.XDocument xDoc = XDocument.Load("full/path/to/trx");
System.Xml.Linq.XNamespace defaultNs = "http://microsoft.com/schemas/VisualStudio/TeamTest/2010";
List<System.Xml.Linq.XElement> UnitTestResultNode = (from data in xDoc.Descendants(defaultNs + "Results")
select data).Descendants(defaultNs + "UnitTestResult").ToList();
var failedset = (from src in UnitTestResultNode
where src.Attribute("outcome").Value == "Failed"
select new { src.Attribute("testName").Value }).ToList();
after you get the failed the cases, you can pass to VStest test agent.
Upvotes: 0
Reputation: 1072
I faced a similar problem. Occasionally a test would fail because of an external resource, failing the entire run. I tried to find a simple solution to your problem, but after much research I didn't - once a test has failed you cannot change its outcome in the same run.
My final solution was to write an external script (doesn't even have to be in C#) that runs tests using VSTest.console.exe or MSTest.exe, parses the resulting trx and then decides which tests to rerun. It is not a very complicated task, since extracting the names and errors of the failed tests from the trx is easy with any decent xml-library.
Upvotes: 1