-
Notifications
You must be signed in to change notification settings - Fork 103
/
NUnitEventListenerOutputTests.cs
124 lines (103 loc) · 5.46 KB
/
NUnitEventListenerOutputTests.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
using System.Collections.Generic;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using NSubstitute;
using NUnit.Framework;
using NUnit.VisualStudio.TestAdapter.Dump;
using NUnit.VisualStudio.TestAdapter.NUnitEngine;
namespace NUnit.VisualStudio.TestAdapter.Tests
{
/// <summary>
/// These tests ensure correct console output, which is what we send to the "recorder".
/// </summary>
public class NUnitEventListenerOutputTests
{
private ITestExecutionRecorder recorder;
private ITestConverterCommon converter;
private IAdapterSettings settings;
private INUnit3TestExecutor executor;
private const string TestOutputProgress =
@"<test-output stream='Progress' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[Whatever
]]></test-output>";
private const string TestOutputOut =
@"<test-output stream='Out' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[Whatever
]]></test-output>";
private const string TestOutputError =
@"<test-output stream='Error' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[Whatever
]]></test-output>";
private const string BlankTestOutput =
@"<test-output stream='Progress' testid='0-1001' testname='Something.TestClass.Whatever'><![CDATA[ ]]></test-output>";
private const string TestFinish =
@"<test-case id='0-1001' name='Test1' fullname='UnitTests.Test1' methodname='Test1' classname='UnitTests' runstate='Runnable' seed='108294034' result='Passed' start-time='2018-10-15 09:41:24Z' end-time='2018-10-15 09:41:24Z' duration='0.000203' asserts='0' parentId='0-1000' />";
/// <summary>
/// For Issue 811.
/// </summary>
private const string TestFinishWithExplicitFixture =
@"<test-case id='0-1001' name='ExplicitTest' fullname='NUnit3VSIssue811.Explicit.ExplicitTest' methodname='ExplicitTest' classname='NUnit3VSIssue811.Explicit' runstate='Runnable' seed='1980958818' result='Skipped' label='Explicit' site='Parent' start-time='0001-01-01T00:00:00.0000000' end-time='0001-01-01T00:00:00.0000000' duration='0.000000' asserts='0' parentId='0-1000'/>";
[SetUp]
public void Setup()
{
recorder = Substitute.For<IFrameworkHandle>();
converter = Substitute.For<ITestConverterCommon>();
settings = Substitute.For<IAdapterSettings>();
settings.ConsoleOut.Returns(1);
executor = Substitute.For<INUnit3TestExecutor>();
executor.Settings.Returns(settings);
executor.FrameworkHandle.Returns(recorder);
}
[Test]
public void ThatNormalTestOutputIsOutput()
{
var sut = new NUnitEventListener(converter, executor);
sut.OnTestEvent(TestOutputOut);
sut.OnTestEvent(TestFinish);
recorder.Received().SendMessage(Arg.Any<TestMessageLevel>(), Arg.Is<string>(x => x.StartsWith("Whatever")));
converter.Received().GetVsTestResults(Arg.Any<NUnitTestEventTestCase>(), Arg.Is<ICollection<INUnitTestEventTestOutput>>(x => x.Count == 1));
}
[Test]
public void ThatProgressTestOutputIsOutput()
{
var sut = new NUnitEventListener(converter, executor);
sut.OnTestEvent(TestOutputProgress);
sut.OnTestEvent(TestFinish);
recorder.Received().SendMessage(Arg.Any<TestMessageLevel>(), Arg.Is<string>(x => x.StartsWith("Whatever")));
converter.Received().GetVsTestResults(Arg.Any<NUnitTestEventTestCase>(), Arg.Is<ICollection<INUnitTestEventTestOutput>>(x => x.Count == 1));
}
[Test]
public void ThatNormalTestOutputIsError()
{
var sut = new NUnitEventListener(converter, executor);
sut.OnTestEvent(TestOutputError);
sut.OnTestEvent(TestFinish);
recorder.Received().SendMessage(Arg.Any<TestMessageLevel>(), Arg.Is<string>(x => x.StartsWith("Whatever")));
converter.Received().GetVsTestResults(Arg.Any<NUnitTestEventTestCase>(), Arg.Is<ICollection<INUnitTestEventTestOutput>>(x => x.Count == 1));
}
[Test]
public void ThatConsoleOutCanStopAllTestOutput()
{
settings.ConsoleOut.Returns(0);
var sut = new NUnitEventListener(converter, executor);
sut.OnTestEvent(TestOutputOut);
sut.OnTestEvent(TestOutputProgress);
sut.OnTestEvent(TestOutputError);
sut.OnTestEvent(TestFinish);
recorder.DidNotReceive().SendMessage(Arg.Any<TestMessageLevel>(), Arg.Any<string>());
}
[Test]
public void ThatTestOutputWithOnlyWhiteSpaceIsNotOutput()
{
var sut = new NUnitEventListener(converter, executor);
sut.OnTestEvent(BlankTestOutput);
recorder.DidNotReceive().SendMessage(Arg.Any<TestMessageLevel>(), Arg.Any<string>());
}
/// <summary>
/// Issue 811 System.FormatException: The UTC representation of the date falls outside the year range 1-9999" from skipped test in Eastern European time zone.
/// </summary>
[Test]
public void ThatExplicitTestFixtureWorksWithZeroStartTime()
{
var sut = new NUnitEventListener(converter, executor);
Assert.DoesNotThrow(() => sut.OnTestEvent(TestFinishWithExplicitFixture));
}
}
}