Skip to content

Commit 89d1960

Browse files
authored
Merge pull request #1191 from nunit/fix1186
Create dummy test case for the assembly when the execution fails.
2 parents e0c21e5 + d1e1296 commit 89d1960

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

NUnit3TestAdapter.sln.DotSettings

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
88
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AA_BB" /&gt;&lt;/Policy&gt;</s:String>
99
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp70</s:String>
10+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=15b5b1f1_002D457c_002D4ca6_002Db278_002D5615aedc07d3/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static readonly fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AA_BB" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
11+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=236f7aa5_002D7b06_002D43ca_002Dbf2a_002D9b31bfcff09a/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Private" Description="Constant fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="CONSTANT_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AA_BB" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
12+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=4a98fdf6_002D7d98_002D4f5a_002Dafeb_002Dea44ad98c70c/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
13+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=f9fce829_002De6f4_002D4cb2_002D80f1_002D5497c44f51df/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
14+
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
1015
<s:Boolean x:Key="/Default/UserDictionary/Words/=mstest/@EntryIndexedValue">True</s:Boolean>
1116
<s:Boolean x:Key="/Default/UserDictionary/Words/=nunit/@EntryIndexedValue">True</s:Boolean>
1217
<s:Boolean x:Key="/Default/UserDictionary/Words/=Parallelization/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

build.cake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var configuration = Argument("configuration", "Release");
1515

1616
var version = "4.6.0";
1717

18-
var modifier = "-beta.2";
18+
var modifier = "-beta.7";
1919

2020
var dbgSuffix = configuration.ToLower() == "debug" ? "-dbg" : "";
2121
var packageVersion = version + modifier + dbgSuffix;

src/NUnitTestAdapter/NUnit3TestDiscoverer.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove
123123
}
124124
else
125125
{
126-
TestLog.Warning("Exception thrown discovering tests in " + sourceAssembly, e);
126+
TestLog.Error("Exception thrown discovering tests in " + sourceAssembly, e);
127+
// throw; // This causes the VerifyLoading test to fail. It can't load the Empty assembly, which happens regardless of this, just when rethrowing it shows up.
127128
}
128129
}
129130
catch (BadImageFormatException)
@@ -145,13 +146,19 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove
145146
catch (TypeLoadException ex)
146147
{
147148
if (ex.TypeName == "NUnit.Framework.Api.FrameworkController")
149+
{
148150
TestLog.Warning(" Skipping NUnit 2.x test assembly");
151+
}
149152
else
150-
TestLog.Warning("Exception thrown discovering tests in " + sourceAssembly, ex);
153+
{
154+
TestLog.Error("Exception thrown discovering tests in " + sourceAssembly, ex);
155+
throw;
156+
}
151157
}
152158
catch (Exception ex)
153159
{
154-
TestLog.Warning("Exception thrown discovering tests in " + sourceAssembly, ex);
160+
TestLog.Error("Exception thrown discovering tests in " + sourceAssembly, ex);
161+
throw;
155162
}
156163
finally
157164
{

src/NUnitTestAdapter/NUnit3TestExecutor.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
3333
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
34+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
3435

3536
using NUnit.Engine;
3637
using NUnit.VisualStudio.TestAdapter.Dump;
@@ -142,7 +143,7 @@ private void RunAssemblies(IEnumerable<string> sources, TestFilter filter)
142143
string assemblyPath = Path.IsPathRooted(assemblyName)
143144
? assemblyName
144145
: Path.Combine(Directory.GetCurrentDirectory(), assemblyName);
145-
RunAssembly(assemblyPath, null, filter);
146+
RunAssembly(assemblyPath, null, filter, assemblyName);
146147
}
147148
catch (Exception ex)
148149
{
@@ -205,13 +206,13 @@ public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrame
205206
var filterBuilder = CreateTestFilterBuilder();
206207
var filter = filterBuilder.FilterByList(assemblyGroup);
207208

208-
RunAssembly(assemblyPath, assemblyGroup, filter);
209+
RunAssembly(assemblyPath, assemblyGroup, filter, assemblyName);
209210
}
210211
catch (Exception ex)
211212
{
212213
if (ex is TargetInvocationException) { ex = ex.InnerException; }
213214

214-
TestLog.Warning("Exception thrown executing tests", ex);
215+
TestLog.Error("Exception thrown executing tests", ex);
215216
}
216217

217218
assemblytiming.LogTime($"Executing {assemblyGroup.Key} time ");
@@ -274,7 +275,8 @@ public void InitializeForExecution(IRunContext runContext, IFrameworkHandle fram
274275
TestLog.Debug("EnableShutdown: " + enableShutdown);
275276
}
276277

277-
private void RunAssembly(string assemblyPath, IGrouping<string, TestCase> testCases, TestFilter filter)
278+
private void RunAssembly(string assemblyPath, IGrouping<string, TestCase> testCases, TestFilter filter,
279+
string assemblyName)
278280
{
279281
LogActionAndSelection(assemblyPath, filter);
280282
RestoreRandomSeed(assemblyPath);
@@ -326,6 +328,20 @@ private void RunAssembly(string assemblyPath, IGrouping<string, TestCase> testCa
326328
if (ex is TargetInvocationException)
327329
ex = ex.InnerException;
328330
TestLog.Warning(" Exception thrown executing tests in " + assemblyPath, ex);
331+
var tc = new TestCase(assemblyName, new Uri(NUnit3TestExecutor.ExecutorUri), assemblyName)
332+
{
333+
DisplayName = assemblyName,
334+
FullyQualifiedName = assemblyName,
335+
Id = Guid.NewGuid(),
336+
CodeFilePath = assemblyPath,
337+
LineNumber = 0,
338+
};
339+
FrameworkHandle.RecordResult(new TestResult(tc)
340+
{
341+
Outcome = TestOutcome.Failed,
342+
ErrorMessage = ex.ToString(),
343+
ErrorStackTrace = ex.StackTrace,
344+
});
329345
}
330346
finally
331347
{

src/NUnitTestAdapterTests/TestDiscoveryTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public class EmptyAssemblyDiscoveryTests : ITestCaseDiscoverySink
127127
static readonly string EmptyAssemblyPath =
128128
Path.Combine(TestContext.CurrentContext.TestDirectory, "empty-assembly.dll");
129129

130+
// [Ignore("This test fails in the engine when loading an empty test, with a TargetInvocationException exception")]
130131
[TestCaseSource(typeof(TestDiscoveryDataProvider), nameof(TestDiscoveryDataProvider.TestDiscoveryData))]
131132
public void VerifyLoading(IDiscoveryContext context)
132133
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy