Skip to content

Commit f4b727e

Browse files
committed
Fix missing outcomes.
1 parent 3a775d8 commit f4b727e

File tree

4 files changed

+231
-61
lines changed

4 files changed

+231
-61
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
[![Github Releases](https://img.shields.io/github/release/xkbeyer/CatchTestAdapter/all.svg?label=pre-release)](https://github.com/xkbeyer/CatchTestAdapter/releases)
21
[![Github Releases](https://img.shields.io/github/release/xkbeyer/CatchTestAdapter.svg)](https://github.com/xkbeyer/CatchTestAdapter/releases)
2+
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
33
# CatchTestAdapter
44
A Visual Studio Extension to run [Catch2](https://github.com/catchorg/Catch2) unit tests within the Visual Studio TestExplorer.
55

@@ -8,26 +8,25 @@ Use the latest [CatchTestAdapter.vsix](https://github.com/xkbeyer/CatchTestAdapt
88
It can be installed by double clicking on the downloaded file.
99

1010
### Visual Studio Compatibility
11-
v1.6.x: Visual Studio 2019 v16.2 and newer
12-
11+
##### v1.6.x: Works with Visual Studio 2019 v16.2 and newer
1312
Beginning with Visual Studio 2019 v16.2 the CatchTestAdapter 1.5.1 is broken.
14-
The new TextExplorer Window doesn't accept new test cases as a sub test case.
15-
Therefore Catch SECTIONs are no longer shown as test cases after the discovery phase.
16-
They are shown as sub results.
13+
The new TestExplorer Window doesn't accept new test cases as a sub test case.
14+
As a result the Catch2 `SECTION`s are no longer shown as sub test cases after the first run.
15+
Now they are shown as sub results of a test case.
1716

18-
v1.5.1: Visual Studio prior v16.2
17+
##### v1.5.1: Works with Visual Studio prior to v16.2
1918

2019
### Status
2120

2221
- Test cases are shown after discovery process.
2322
- Stack trace link to the source line.
24-
- Catch2 TAGS are implemented as Traits.
25-
- SECTION and SCENARIO are shown as sub results.
23+
- Catch2 `TAGS` are implemented as Traits.
24+
- `SECTION` and `SCENARIO` are shown as sub results.
2625

2726
### Testing
2827
To run the unit tests against the `CatchTestAdapter.dll` of the solution, the `Local.runsettings` file must be loaded.
2928
The `TestAdaptersPaths` should be adapted to point to the Solution directory.
30-
```
29+
```xml
3130
<TestAdaptersPaths>c:\Path\to\the\Solution\bin\Debug</TestAdaptersPaths>
3231
```
3332

TestAdapter/CatchTestCase.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public TestCase[] Sections {
4242
}
4343
[XmlElement("OverallResult", typeof(OverallResult))]
4444
public OverallResult Result { get; set; }
45+
[XmlElement("OverallResults", typeof(OverallResults), IsNullable = true)]
46+
public OverallResults Results { get; set; }
4547
}
4648
public class Failure
4749
{
@@ -75,4 +77,15 @@ public class OverallResult
7577
[XmlAttribute("durationInSeconds")]
7678
public string Duration = "";
7779
}
80+
public class OverallResults
81+
{
82+
[XmlAttribute("successes")]
83+
public string Successes = "";
84+
[XmlAttribute("failures")]
85+
public string Failures = "";
86+
[XmlAttribute("expectedFailures")]
87+
public string ExpectedFailures = "";
88+
[XmlAttribute("durationInSeconds")]
89+
public string Duration = "";
90+
}
7891
}

TestAdapter/TestExecutor.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,21 @@ private void CreateResult(Tests.TestCase element, TestCase testCase, string name
151151
DisplayName = name.Replace(".", "\n\t"),
152152
ErrorMessage = $"",
153153
ErrorStackTrace = "",
154+
Outcome = TestOutcome.None
154155
};
156+
155157
if (element.Result != null)
158+
{
159+
subResult.Outcome = element.Result.Success == "true" ? TestOutcome.Passed : TestOutcome.Failed;
156160
subResult.Duration = TimeSpan.FromSeconds(Double.Parse(element.Result.Duration, CultureInfo.InvariantCulture));
161+
}
157162

158163
int failedExpressions = ConstructResult(element.Expressions, subResult);
164+
// Make sure the outcome is failed if the expressions have failed.
165+
if (failedExpressions != 0)
166+
{
167+
subResult.Outcome = TestOutcome.Failed;
168+
}
159169

160170
foreach (var s in (element.Warning ?? new string[] { }))
161171
{
@@ -179,7 +189,18 @@ private void CreateResult(Tests.TestCase element, TestCase testCase, string name
179189
subResult.ErrorStackTrace += $"at #{failedExpressions} - {name}() in {FilePath}:line {LineNumber}{Environment.NewLine}";
180190
}
181191

182-
subResult.Outcome = failedExpressions == 0 ? TestOutcome.Passed : TestOutcome.Failed;
192+
if( subResult.Outcome == TestOutcome.None )
193+
{
194+
// Check if the OverallResults is set with an outcome.
195+
if (element.Results != null)
196+
{
197+
if (Int32.Parse(element.Results.Failures) != 0)
198+
subResult.Outcome = TestOutcome.Failed;
199+
else
200+
subResult.Outcome = TestOutcome.Passed;
201+
}
202+
}
203+
183204
results.Add(subResult);
184205

185206
// Try to find the failure from a subsection of this element.

0 commit comments

Comments
 (0)