forked from csoltenborn/GoogleTestAdapter
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathXmlTestResultParserTests.cs
More file actions
194 lines (157 loc) · 8.3 KB
/
XmlTestResultParserTests.cs
File metadata and controls
194 lines (157 loc) · 8.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using System;
using System.Collections.Generic;
using FluentAssertions;
using GoogleTestAdapter.Helpers;
using GoogleTestAdapter.Tests.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using static GoogleTestAdapter.Tests.Common.TestMetadata.TestCategories;
namespace GoogleTestAdapter.TestResults
{
[TestClass]
public class XmlTestResultParserTests : TestsBase
{
[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_FileDoesNotExist_WarningAndEmptyResult()
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("BarSuite.BazTest1", "FooSuite.BarTest",
"FooSuite.BazTest", "BarSuite.BazTest2");
var parser = new XmlTestResultParser(testCases, "somefile", TestEnvironment.Logger);
List<Model.TestResult> results = parser.GetTestResults();
results.Count.Should().Be(0);
MockLogger.Verify(l => l.LogWarning(It.IsAny<string>()), Times.Exactly(1));
}
[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_InvalidFile_WarningAndEmptyResult()
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("GoogleTestSuiteName1.TestMethod_001",
"GoogleTestSuiteName1.TestMethod_002");
MockOptions.Setup(o => o.DebugMode).Returns(true);
var parser = new XmlTestResultParser(testCases, TestResources.XmlFileBroken, TestEnvironment.Logger);
List<Model.TestResult> results = parser.GetTestResults();
results.Count.Should().Be(0);
MockLogger.Verify(l => l.DebugWarning(It.IsAny<string>()), Times.Exactly(1));
}
[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_FileWithInvalidStatusAttribute_WarningAndEmptyResult()
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("GoogleTestSuiteName1.TestMethod_001",
"GoogleTestSuiteName1.TestMethod_002");
MockOptions.Setup(o => o.DebugMode).Returns(true);
var parser = new XmlTestResultParser(testCases, TestResources.XmlFileBroken_InvalidStatusAttibute, TestEnvironment.Logger);
List<Model.TestResult> results = parser.GetTestResults();
results.Count.Should().Be(1);
MockLogger.Verify(l => l.DebugWarning(It.IsAny<string>()), Times.Exactly(1));
}
[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_Sample1_FindsPassedAndSkipptedResults()
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("GoogleTestSuiteName1.TestMethod_001", "SimpleTest.DISABLED_TestMethodDisabled");
var parser = new XmlTestResultParser(testCases, TestResources.XmlFile1, TestEnvironment.Logger);
List<Model.TestResult> results = parser.GetTestResults();
results.Count.Should().Be(2);
AssertTestResultIsPassed(results[0]);
AssertTestResultIsSkipped(results[1]);
}
[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_Sample1_UnexpectedTestOutcome_LogsErrorAndThrows()
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("GoogleTestSuiteName1.TestMethod_007");
var parser = new XmlTestResultParser(testCases, TestResources.XmlFile1, TestEnvironment.Logger);
parser.Invoking(p => p.GetTestResults()).Should().NotThrow<Exception>();
MockLogger.Verify(l => l.LogError(It.Is<string>(s => s.Contains("Foo"))), Times.Exactly(1));
}
[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_Sample1_FindsPassedParameterizedResult()
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("ParameterizedTestsTest1/AllEnabledTest.TestInstance/7");
var parser = new XmlTestResultParser(testCases, TestResources.XmlFile1, TestEnvironment.Logger);
List<Model.TestResult> results = parser.GetTestResults();
results.Count.Should().Be(1);
AssertTestResultIsPassed(results[0]);
}
[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_Sample1_FindsFailureResult()
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.ToTestCase("AnimalsTest.testGetEnoughAnimals", TestDataCreator.DummyExecutable, @"x:\prod\company\util\util.cpp").Yield();
var parser = new XmlTestResultParser(testCases, TestResources.XmlFile1, TestEnvironment.Logger);
List<Model.TestResult> results = parser.GetTestResults();
results.Count.Should().Be(1);
string ErrorMsg = @"Value of: animals.size()
Actual: 1
Expected: 3
Should get three animals";
AssertTestResultIsFailure(results[0], ErrorMsg);
results[0].ErrorStackTrace.Should().Contain(@"x:\prod\company\util\util.cpp");
}
[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_Sample1_FindsParamterizedFailureResult()
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.ToTestCase("ParameterizedTestsTest1/AllEnabledTest.TestInstance/11", TestDataCreator.DummyExecutable, @"someSimpleParameterizedTest.cpp").Yield();
var parser = new XmlTestResultParser(testCases, TestResources.XmlFile1, TestEnvironment.Logger);
List<Model.TestResult> results = parser.GetTestResults();
results.Count.Should().Be(1);
string errorMsg = @"Expected: (0) != ((pGSD->g_outputs64[(g_nOutput[ 8 ]-1)/64] & g_dnOutput[g_nOutput[ 8 ]])), actual: 0 vs 0";
AssertTestResultIsFailure(results[0], errorMsg);
results[0].ErrorStackTrace.Should().Contain(@"someSimpleParameterizedTest.cpp");
}
[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_Sample2_FindsPassedResult()
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.CreateDummyTestCases("FooTest.DoesXyz");
var parser = new XmlTestResultParser(testCases, TestResources.XmlFile2, TestEnvironment.Logger);
List<Model.TestResult> results = parser.GetTestResults();
results.Count.Should().Be(1);
AssertTestResultIsPassed(results[0]);
}
[TestMethod]
[TestCategory(Unit)]
public void GetTestResults_Sample2_FindsFailureResult()
{
IEnumerable<Model.TestCase> testCases = TestDataCreator.ToTestCase("FooTest.MethodBarDoesAbc", TestDataCreator.DummyExecutable,
@"c:\prod\gtest-1.7.0\staticallylinkedgoogletests\main.cpp").Yield();
var parser = new XmlTestResultParser(testCases, TestResources.XmlFile2, TestEnvironment.Logger);
List<Model.TestResult> results = parser.GetTestResults();
results.Count.Should().Be(1);
string ErrorMsg = @"#1 - Value of: output_filepath
Actual: ""this/package/testdata/myoutputfile.dat""
Expected: input_filepath
Which is: ""this/package/testdata/myinputfile.dat""
Something's not right!!
#2 - Value of: 56456
Expected: 12312
Something's wrong :(";
AssertTestResultIsFailure(results[0], ErrorMsg);
results[0].ErrorStackTrace.Should().Contain(@"c:\prod\gtest-1.7.0\staticallylinkedgoogletests\main.cpp");
}
public static void AssertTestResultIsPassed(Model.TestResult testResult)
{
testResult.Outcome.Should().Be(Model.TestOutcome.Passed);
testResult.ErrorMessage.Should().BeNull();
}
public static void AssertTestResultIsSkipped(Model.TestResult testResult)
{
testResult.Outcome.Should().Be(Model.TestOutcome.Skipped);
testResult.ErrorMessage.Should().BeNull();
}
private void AssertTestResultIsFailure(Model.TestResult testResult, string errorMessage)
{
AssertTestResultIsFailure(testResult);
testResult.ErrorMessage.Replace("\r\n", "\n").Should().Be(errorMessage.Replace("\r\n", "\n"));
}
public static void AssertTestResultIsFailure(Model.TestResult testResult)
{
testResult.Outcome.Should().Be(Model.TestOutcome.Failed);
testResult.ErrorMessage.Should().NotBeNull();
}
}
}