Skip to content

Commit 284b6f5

Browse files
committed
Add unit tests of netcore3.1 driver
1 parent 11c875c commit 284b6f5

File tree

6 files changed

+168
-22
lines changed

6 files changed

+168
-22
lines changed

src/Directory.Build.props

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<Project>
22

3-
<PropertyGroup>
4-
<OutputPath>..\..\..\bin\$(Configuration)\</OutputPath>
5-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
6-
<LangVersion>11</LangVersion>
7-
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
8-
<Company>NUnit Software</Company>
9-
<Copyright>Copyright (c) 2022 Charlie Poole, Rob Prouse</Copyright>
10-
</PropertyGroup>
11-
12-
<PropertyGroup Condition="'$(Version)'==''">
13-
<AssemblyVersion>3.0.0.0</AssemblyVersion>
14-
<FileVersion>3.99.0.0</FileVersion>
15-
<InformationalVersion>3.99.0.0-VSIDE</InformationalVersion>
16-
</PropertyGroup>
3+
<PropertyGroup>
4+
<!-- Compile and Build Settings -->
5+
<LangVersion>12</LangVersion>
6+
<Features>strict</Features>
7+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8+
<Version Condition="'$(Version)'==''">3.99.0.0</Version>
9+
<OutputPath>$(MSBuildThisFileDirectory)\..\bin\$(Configuration)\</OutputPath>
10+
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
11+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
12+
<!-- Informational Settings -->
13+
<Company>NUnit Software</Company>
14+
<Copyright>Copyright (c) 2022 Charlie Poole, Rob Prouse</Copyright>
15+
</PropertyGroup>
1716

1817
</Project>

src/NUnitEngine/nunit.engine.core.tests/Drivers/NUnit3FrameworkDriverTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public void RunTestsAction_AfterLoad_ReturnsRunnableSuite()
104104
public void RunTestsAction_WithoutLoad_ThrowsInvalidOperationException()
105105
{
106106
var ex = Assert.Catch(() => _driver.Run(new NullListener(), TestFilter.Empty.Text));
107+
if (ex is TargetInvocationException)
108+
ex = ex.InnerException;
107109
Assert.That(ex, Is.TypeOf<InvalidOperationException>());
108110
Assert.That(ex.Message, Is.EqualTo(LOAD_MESSAGE));
109111
}
@@ -118,12 +120,6 @@ public void RunTestsAction_WithInvalidFilterElement_ThrowsNUnitEngineException()
118120
Assert.That(ex, Is.TypeOf<NUnitEngineException>());
119121
}
120122

121-
private static string GetSkipReason(XmlNode result)
122-
{
123-
var propNode = result.SelectSingleNode(string.Format("properties/property[@name='{0}']", PropertyNames.SkipReason));
124-
return propNode == null ? null : propNode.GetAttribute("value");
125-
}
126-
127123
private class CallbackEventHandler : System.Web.UI.ICallbackEventHandler
128124
{
129125
private string _result;
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
2+
3+
#if NETCOREAPP
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Reflection;
7+
using System.Xml;
8+
using NUnit.Tests.Assemblies;
9+
using NUnit.Framework;
10+
using NUnit.Framework.Internal;
11+
using System.Runtime.Loader;
12+
13+
namespace NUnit.Engine.Drivers.Tests
14+
{
15+
// Functional tests of the NUnitFrameworkDriver calling into the framework.
16+
public class NUnitNetCore31DriverTests
17+
{
18+
private const string MOCK_ASSEMBLY = "mock-assembly.dll";
19+
private const string LOAD_MESSAGE = "Method called without calling Load first";
20+
21+
private IDictionary<string, object> _settings = new Dictionary<string, object>();
22+
23+
private NUnitNetCore31Driver _driver;
24+
private string _mockAssemblyPath;
25+
26+
[SetUp]
27+
public void CreateDriver()
28+
{
29+
var assemblyName = typeof(NUnit.Framework.TestAttribute).Assembly.GetName();
30+
_mockAssemblyPath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, MOCK_ASSEMBLY);
31+
_driver = new NUnitNetCore31Driver();
32+
}
33+
34+
[Test]
35+
public void Load_GoodFile_ReturnsRunnableSuite()
36+
{
37+
var result = XmlHelper.CreateXmlNode(_driver.Load(_mockAssemblyPath, _settings));
38+
39+
Assert.That(result.Name, Is.EqualTo("test-suite"));
40+
Assert.That(result.GetAttribute("type"), Is.EqualTo("Assembly"));
41+
Assert.That(result.GetAttribute("runstate"), Is.EqualTo("Runnable"));
42+
Assert.That(result.GetAttribute("testcasecount"), Is.EqualTo(MockAssembly.Tests.ToString()));
43+
Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
44+
}
45+
46+
[Test]
47+
public void Explore_AfterLoad_ReturnsRunnableSuite()
48+
{
49+
_driver.Load(_mockAssemblyPath, _settings);
50+
var result = XmlHelper.CreateXmlNode(_driver.Explore(TestFilter.Empty.Text));
51+
52+
Assert.That(result.Name, Is.EqualTo("test-suite"));
53+
Assert.That(result.GetAttribute("type"), Is.EqualTo("Assembly"));
54+
Assert.That(result.GetAttribute("runstate"), Is.EqualTo("Runnable"));
55+
Assert.That(result.GetAttribute("testcasecount"), Is.EqualTo(MockAssembly.Tests.ToString()));
56+
Assert.That(result.SelectNodes("test-suite").Count, Is.GreaterThan(0), "Explore result should have child tests");
57+
}
58+
59+
[Test]
60+
public void ExploreTestsAction_WithoutLoad_ThrowsInvalidOperationException()
61+
{
62+
var ex = Assert.Catch(() => _driver.Explore(TestFilter.Empty.Text));
63+
if (ex is System.Reflection.TargetInvocationException)
64+
ex = ex.InnerException;
65+
Assert.That(ex, Is.TypeOf<InvalidOperationException>());
66+
Assert.That(ex.Message, Is.EqualTo(LOAD_MESSAGE));
67+
}
68+
69+
[Test]
70+
public void CountTestsAction_AfterLoad_ReturnsCorrectCount()
71+
{
72+
_driver.Load(_mockAssemblyPath, _settings);
73+
Assert.That(_driver.CountTestCases(TestFilter.Empty.Text), Is.EqualTo(MockAssembly.Tests));
74+
}
75+
76+
[Test]
77+
public void CountTestsAction_WithoutLoad_ThrowsInvalidOperationException()
78+
{
79+
var ex = Assert.Catch(() => _driver.CountTestCases(TestFilter.Empty.Text));
80+
if (ex is System.Reflection.TargetInvocationException)
81+
ex = ex.InnerException;
82+
Assert.That(ex, Is.TypeOf<InvalidOperationException>());
83+
Assert.That(ex.Message, Is.EqualTo(LOAD_MESSAGE));
84+
}
85+
86+
[Test]
87+
public void RunTestsAction_AfterLoad_ReturnsRunnableSuite()
88+
{
89+
_driver.Load(_mockAssemblyPath, _settings);
90+
var result = XmlHelper.CreateXmlNode(_driver.Run(new NullListener(), TestFilter.Empty.Text));
91+
92+
Assert.That(result.Name, Is.EqualTo("test-suite"));
93+
Assert.That(result.GetAttribute("type"), Is.EqualTo("Assembly"));
94+
Assert.That(result.GetAttribute("runstate"), Is.EqualTo("Runnable"));
95+
Assert.That(result.GetAttribute("testcasecount"), Is.EqualTo(MockAssembly.Tests.ToString()));
96+
Assert.That(result.GetAttribute("result"), Is.EqualTo("Failed"));
97+
Assert.That(result.GetAttribute("passed"), Is.EqualTo(MockAssembly.PassedInAttribute.ToString()));
98+
Assert.That(result.GetAttribute("failed"), Is.EqualTo(MockAssembly.Failed.ToString()));
99+
Assert.That(result.GetAttribute("skipped"), Is.EqualTo(MockAssembly.Skipped.ToString()));
100+
Assert.That(result.GetAttribute("inconclusive"), Is.EqualTo(MockAssembly.Inconclusive.ToString()));
101+
Assert.That(result.SelectNodes("test-suite").Count, Is.GreaterThan(0), "Explore result should have child tests");
102+
}
103+
104+
[Test]
105+
public void RunTestsAction_WithoutLoad_ThrowsInvalidOperationException()
106+
{
107+
var ex = Assert.Catch(() => _driver.Run(new NullListener(), TestFilter.Empty.Text));
108+
if (ex is TargetInvocationException)
109+
ex = ex.InnerException;
110+
Assert.That(ex, Is.TypeOf<InvalidOperationException>());
111+
Assert.That(ex.Message, Is.EqualTo(LOAD_MESSAGE));
112+
}
113+
114+
[Test]
115+
public void RunTestsAction_WithInvalidFilterElement_ThrowsNUnitEngineException()
116+
{
117+
_driver.Load(_mockAssemblyPath, _settings);
118+
119+
var invalidFilter = "<filter><invalidElement>foo</invalidElement></filter>";
120+
var ex = Assert.Catch(() => _driver.Run(new NullListener(), invalidFilter));
121+
Assert.That(ex, Is.TypeOf<TargetInvocationException>());
122+
Assert.That(ex.InnerException, Is.TypeOf<ArgumentException>());
123+
}
124+
125+
private class CallbackEventHandler : System.Web.UI.ICallbackEventHandler
126+
{
127+
private string _result;
128+
129+
public string GetCallbackResult()
130+
{
131+
return _result;
132+
}
133+
134+
public void RaiseCallbackEvent(string eventArgument)
135+
{
136+
_result = eventArgument;
137+
}
138+
}
139+
140+
public class NullListener : ITestEventListener
141+
{
142+
public void OnTestEvent(string testEvent)
143+
{
144+
// No action
145+
}
146+
}
147+
}
148+
}
149+
#endif

src/NUnitEngine/nunit.engine.core.tests/Drivers/NUnitNetStandardDriverTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Reflection;
78
using System.Xml;
89
using NUnit.Tests.Assemblies;
910
using NUnit.Framework;
@@ -106,7 +107,7 @@ public void RunTestsAction_AfterLoad_ReturnsRunnableSuite()
106107
public void RunTestsAction_WithoutLoad_ThrowsInvalidOperationException()
107108
{
108109
var ex = Assert.Catch(() => _driver.Run(new NullListener(), TestFilter.Empty.Text));
109-
if (ex is System.Reflection.TargetInvocationException)
110+
if (ex is TargetInvocationException)
110111
ex = ex.InnerException;
111112
Assert.That(ex, Is.TypeOf<InvalidOperationException>());
112113
Assert.That(ex.Message, Is.EqualTo(LOAD_MESSAGE));

src/NUnitEngine/nunit.engine.core.tests/Internal/ExtensionAssemblyTrackerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class ExtensionAssemblyTrackerTests
2626
public void CreateTracker()
2727
{
2828
_tracker = new ExtensionAssemblyTracker();
29+
Console.WriteLine($"Current assembly version is {THIS_ASSEMBLY_VERSION}");
2930
}
3031

3132
[Test]

src/NUnitEngine/nunit.engine.core/Drivers/NUnitNetStandardDriver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
22

3-
#if NETSTANDARD
3+
#if NETSTANDARD2_0
44
using System;
55
using System.Linq;
66
using System.Collections.Generic;

0 commit comments

Comments
 (0)