Skip to content

Commit

Permalink
Merge pull request #1191 from nunit/fix1186
Browse files Browse the repository at this point in the history
Create dummy test case for the assembly when the execution fails.
  • Loading branch information
OsirisTerje committed Jul 18, 2024
2 parents e0c21e5 + d1e1296 commit 89d1960
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
5 changes: 5 additions & 0 deletions NUnit3TestAdapter.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<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>
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp70</s:String>
<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>
<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>
<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>
<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>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=mstest/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=nunit/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Parallelization/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Expand Down
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var configuration = Argument("configuration", "Release");

var version = "4.6.0";

var modifier = "-beta.2";
var modifier = "-beta.7";

var dbgSuffix = configuration.ToLower() == "debug" ? "-dbg" : "";
var packageVersion = version + modifier + dbgSuffix;
Expand Down
13 changes: 10 additions & 3 deletions src/NUnitTestAdapter/NUnit3TestDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove
}
else
{
TestLog.Warning("Exception thrown discovering tests in " + sourceAssembly, e);
TestLog.Error("Exception thrown discovering tests in " + sourceAssembly, e);
// 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.
}
}
catch (BadImageFormatException)
Expand All @@ -145,13 +146,19 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove
catch (TypeLoadException ex)
{
if (ex.TypeName == "NUnit.Framework.Api.FrameworkController")
{
TestLog.Warning(" Skipping NUnit 2.x test assembly");
}
else
TestLog.Warning("Exception thrown discovering tests in " + sourceAssembly, ex);
{
TestLog.Error("Exception thrown discovering tests in " + sourceAssembly, ex);
throw;
}
}
catch (Exception ex)
{
TestLog.Warning("Exception thrown discovering tests in " + sourceAssembly, ex);
TestLog.Error("Exception thrown discovering tests in " + sourceAssembly, ex);
throw;
}
finally
{
Expand Down
24 changes: 20 additions & 4 deletions src/NUnitTestAdapter/NUnit3TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

using NUnit.Engine;
using NUnit.VisualStudio.TestAdapter.Dump;
Expand Down Expand Up @@ -142,7 +143,7 @@ private void RunAssemblies(IEnumerable<string> sources, TestFilter filter)
string assemblyPath = Path.IsPathRooted(assemblyName)
? assemblyName
: Path.Combine(Directory.GetCurrentDirectory(), assemblyName);
RunAssembly(assemblyPath, null, filter);
RunAssembly(assemblyPath, null, filter, assemblyName);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -205,13 +206,13 @@ public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrame
var filterBuilder = CreateTestFilterBuilder();
var filter = filterBuilder.FilterByList(assemblyGroup);

RunAssembly(assemblyPath, assemblyGroup, filter);
RunAssembly(assemblyPath, assemblyGroup, filter, assemblyName);
}
catch (Exception ex)
{
if (ex is TargetInvocationException) { ex = ex.InnerException; }

TestLog.Warning("Exception thrown executing tests", ex);
TestLog.Error("Exception thrown executing tests", ex);
}

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

private void RunAssembly(string assemblyPath, IGrouping<string, TestCase> testCases, TestFilter filter)
private void RunAssembly(string assemblyPath, IGrouping<string, TestCase> testCases, TestFilter filter,
string assemblyName)
{
LogActionAndSelection(assemblyPath, filter);
RestoreRandomSeed(assemblyPath);
Expand Down Expand Up @@ -326,6 +328,20 @@ private void RunAssembly(string assemblyPath, IGrouping<string, TestCase> testCa
if (ex is TargetInvocationException)
ex = ex.InnerException;
TestLog.Warning(" Exception thrown executing tests in " + assemblyPath, ex);
var tc = new TestCase(assemblyName, new Uri(NUnit3TestExecutor.ExecutorUri), assemblyName)
{
DisplayName = assemblyName,
FullyQualifiedName = assemblyName,
Id = Guid.NewGuid(),
CodeFilePath = assemblyPath,
LineNumber = 0,
};
FrameworkHandle.RecordResult(new TestResult(tc)
{
Outcome = TestOutcome.Failed,
ErrorMessage = ex.ToString(),
ErrorStackTrace = ex.StackTrace,
});
}
finally
{
Expand Down
1 change: 1 addition & 0 deletions src/NUnitTestAdapterTests/TestDiscoveryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public class EmptyAssemblyDiscoveryTests : ITestCaseDiscoverySink
static readonly string EmptyAssemblyPath =
Path.Combine(TestContext.CurrentContext.TestDirectory, "empty-assembly.dll");

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

0 comments on commit 89d1960

Please sign in to comment.