-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathResultReporterTests.cs
202 lines (174 loc) · 6.81 KB
/
ResultReporterTests.cs
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
195
196
197
198
199
200
201
202
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using NUnit.ConsoleRunner.Options;
using NUnit.Engine;
using NUnit.Framework;
using NUnit.Framework.Api;
using NUnit.TestData.Assemblies;
using NUnit.TextDisplay;
namespace NUnit.ConsoleRunner
{
public class ResultReporterTests
{
private XmlNode _result;
private ResultReporter _reporter;
private StringBuilder _report;
[OneTimeSetUp]
public void CreateResult()
{
var mockAssembly = typeof(MockAssembly).Assembly;
var frameworkSettings = new Dictionary<string, object>
{
{ "TestParameters", "1=d;2=c" },
{ "TestParametersDictionary", new Dictionary<string, string>
{
{ "1", "d" },
{ "2", "c" }
}}
};
var controller = new FrameworkController(mockAssembly, "id", frameworkSettings);
controller.LoadTests();
var xmlText = controller.RunTests(null);
var engineResult = AddMetadata(new TestEngineResult(xmlText));
_result = engineResult.Xml;
Assert.That(_result, Is.Not.Null, "Unable to create report result.");
}
[SetUp]
public void CreateReporter()
{
_report = new StringBuilder();
var writer = new ExtendedTextWrapper(new StringWriter(_report));
_reporter = new ResultReporter(_result, writer, ConsoleMocks.Options());
}
[Test]
public void ReportSequenceTest()
{
var report = GetReport(_reporter.ReportResults);
var reportSequence = new[]
{
"Tests Not Run",
"Errors, Failures and Warnings",
"Test Run Summary"
};
int last = -1;
foreach (string title in reportSequence)
{
var index = report.IndexOf(title);
Assert.That(index > 0, "Report not found: " + title);
Assert.That(index > last, "Report out of sequence: " + title);
last = index;
}
}
[Test]
public void SummaryReportTest()
{
var expected = new[] {
"Test Run Summary",
" Overall result: Failed",
$" Test Count: {MockAssembly.Tests}, Pass: {MockAssembly.Passed}, Fail: 11, Warn: 1, Inconclusive: 1, Skip: 7",
" Failed Tests - Failures: 1, Errors: 7, Invalid: 3",
" Skipped Tests - Ignored: 4, Explicit: 3, Other: 0",
" Start time: 2015-10-19 02:12:28Z",
" End time: 2015-10-19 02:12:29Z",
" Duration: 0.349 seconds",
""
};
var actualSummary = GetReportLines(_reporter.WriteSummaryReport);
Assert.That(actualSummary, Is.EqualTo(expected));
}
[Test]
public void ErrorsAndFailuresReportTest()
{
var nl = Environment.NewLine;
var expected = new[] {
"Errors, Failures and Warnings",
"1) Failed : NUnit.TestData.Assemblies.MockTestFixture.FailingTest" + nl +
"Intentional failure",
"2) Invalid : NUnit.TestData.Assemblies.MockTestFixture.NonPublicTest" + nl +
"Method is not public",
"3) Invalid : NUnit.TestData.Assemblies.MockTestFixture.NotRunnableTest" + nl +
"No arguments were provided",
"4) Error : NUnit.TestData.Assemblies.MockTestFixture.TestWithException" + nl +
"System.Exception : Intentional Exception",
"5) Warning : NUnit.TestData.Assemblies.MockTestFixture.WarningTest" + nl +
"Warning Message",
"6) Invalid : NUnit.TestData.BadFixture" + nl +
"No suitable constructor was found"
};
var actualErrorFailuresReport = GetReport(_reporter.WriteErrorsFailuresAndWarningsReport);
foreach (var ex in expected)
{
Assert.That(actualErrorFailuresReport, Does.Contain(ex));
}
}
[Test]
public void TestsNotRunTest()
{
var expected = new[] {
"Tests Not Run",
"",
"1) Explicit : NUnit.TestData.Assemblies.MockTestFixture.ExplicitTest",
"",
"2) Ignored : NUnit.TestData.Assemblies.MockTestFixture.IgnoreTest",
"Ignore Message",
"",
"3) Explicit : NUnit.TestData.ExplicitFixture.Test1",
"OneTimeSetUp: ",
"",
"4) Explicit : NUnit.TestData.ExplicitFixture.Test2",
"OneTimeSetUp: ",
"",
"5) Ignored : NUnit.TestData.IgnoredFixture.Test1",
"OneTimeSetUp: BECAUSE",
"",
"6) Ignored : NUnit.TestData.IgnoredFixture.Test2",
"OneTimeSetUp: BECAUSE",
"",
"7) Ignored : NUnit.TestData.IgnoredFixture.Test3",
"OneTimeSetUp: BECAUSE",
""
};
var report = GetReportLines(_reporter.WriteNotRunReport);
Assert.That(report, Is.EqualTo(expected));
}
[Test, Explicit("Displays failure behavior")]
public void WarningsOnlyDisplayOnce()
{
Assert.Warn("Just a warning");
}
[Test]
public void TestParameterSettingsWrittenCorrectly()
{
var expected = new[] {
" TestParameters: |1=d;2=c|",
" TestParametersDictionary:",
" 1 -> |d|",
" 2 -> |c|"
};
var report = GetReportLines(_reporter.WriteRunSettingsReport);
Assert.That(report, Is.SupersetOf(expected));
}
private static TestEngineResult AddMetadata(TestEngineResult input)
{
return input.Aggregate("test-run start-time=\"2015-10-19 02:12:28Z\" end-time=\"2015-10-19 02:12:29Z\" duration=\"0.348616\"", string.Empty, string.Empty, string.Empty);
}
private string GetReport(TestDelegate del)
{
del();
return _report.ToString();
}
private IList<string> GetReportLines(TestDelegate del)
{
var rdr = new StringReader(GetReport(del));
string? line;
var lines = new List<string>();
while ((line = rdr.ReadLine()) != null)
lines.Add(line);
return lines;
}
}
}