Skip to content

Commit 7ef55db

Browse files
committed
Report test durations, when they are available. Requires the next version of Catch.
1 parent e2ddb0b commit 7ef55db

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

CatchVsTestAdapter/CatchTestExecutor.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private static XDocument RunOrDebugCatchTest(string testBinary, string testSpec,
125125
/// </summary>
126126
internal static string RunCatchTests(string testBinary, string testSpec)
127127
{
128-
return Utility.runExe(testBinary, testSpec, "--reporter", "xml");
128+
return Utility.runExe(testBinary, testSpec, "-r", "xml", "-d", "yes");
129129
}
130130

131131

@@ -141,7 +141,7 @@ internal static string DebugCatchTest(string testBinary, string testSpec, IFrame
141141
var outputPath = Path.GetTempFileName();
142142
try
143143
{
144-
var arguments = Utility.escapeArguments(testSpec, "--reporter", "xml", "--break", "--out", outputPath);
144+
var arguments = Utility.escapeArguments(testSpec, "-r", "xml", "-b", "-d", "yes", "-o", outputPath);
145145
var debuggee = Process.GetProcessById(framework.LaunchProcessWithDebuggerAttached(exePath, cwd, arguments, null));
146146
debuggee.WaitForExit();
147147
output = File.ReadAllText(outputPath);
@@ -166,6 +166,12 @@ internal static TestResult GetTestResultFromReport(TestCase test, XDocument repo
166166
var testCaseElement = GetTestCaseElement(report, test.FullyQualifiedName);
167167
result.Outcome = GetTestOutcome(testCaseElement);
168168

169+
try
170+
{
171+
result.Duration = GetTestDuration(testCaseElement);
172+
}
173+
catch { } //< Older versions of catch do not include the duration in the xml report.
174+
169175
if (result.Outcome == TestOutcome.Failed)
170176
{
171177
// Look for a expression that caused the test to fail..
@@ -229,13 +235,24 @@ where isMatch(el.Attribute("name").Value, testName)
229235
/// <summary>
230236
/// Returns the outcome of a given test based on its xml element.
231237
/// </summary>
232-
internal static TestOutcome GetTestOutcome(XElement testCaseElememt)
238+
internal static TestOutcome GetTestOutcome(XElement testCaseElement)
233239
{
234-
var status = testCaseElememt.Descendants("OverallResult").First().Attribute("success").Value;
240+
var status = testCaseElement.Descendants("OverallResult").First().Attribute("success").Value;
235241

236242
return (status.ToLower() == "true") ? TestOutcome.Passed : TestOutcome.Failed;
237243
}
238244

245+
246+
/// <summary>
247+
/// Returns the duration of a given test based on its xml element.
248+
/// </summary>
249+
internal static TimeSpan GetTestDuration(XElement testCaseElement)
250+
{
251+
var durationAttr = testCaseElement.Descendants("OverallResult").First().Attribute("durationInSeconds");
252+
return TimeSpan.FromSeconds(double.Parse(durationAttr.Value));
253+
}
254+
255+
239256
#endregion
240257
}
241258
}

0 commit comments

Comments
 (0)