Skip to content

Commit

Permalink
Merge pull request #369 from nunit/Issue-302
Browse files Browse the repository at this point in the history
Removed exception catching and error reporting in GetRunnerFor, since…
  • Loading branch information
OsirisTerje authored Jul 31, 2017
2 parents add074d + 164d948 commit 6454201
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 29 deletions.
Binary file modified NUnit3TestAdapter.sln
Binary file not shown.
4 changes: 2 additions & 2 deletions demo/NUnitTestDemo/NUnit3TestDemo.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.8.0-rc1\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.8.0-rc1\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -78,7 +78,7 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.8.0-rc1\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.8.0-rc1\build\net35\NUnit3TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 1 addition & 1 deletion demo/NUnitTestDemo/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.7.1" targetFramework="net45" />
<package id="NUnit3TestAdapter" version="3.8.0-rc1" targetFramework="net45" />
<package id="NUnit3TestAdapter" version="3.8.0" targetFramework="net45" />
</packages>
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/NUnit3TestDiscoverer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ***********************************************************************
// Copyright (c) 2011-2015 Charlie Poole, Terje Sandstrom
// Copyright (c) 2011-2017 Charlie Poole, Terje Sandstrom
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
Expand Down
12 changes: 1 addition & 11 deletions src/NUnitTestAdapter/NUnitTestAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,7 @@ protected void Initialize(IDiscoveryContext context, IMessageLogger messageLogge
protected ITestRunner GetRunnerFor(string assemblyName)
{
var package = CreateTestPackage(assemblyName);

try
{
return TestEngine.GetRunner(package);
}
catch (Exception ex)
{
TestLog.Error("Error: Unable to get runner for this assembly. Check installation, including any extensions.");
TestLog.Error(ex.GetType().Name + ": " + ex.Message);
throw;
}
return TestEngine.GetRunner(package);
}

private TestPackage CreateTestPackage(string assemblyName)
Expand Down
17 changes: 15 additions & 2 deletions src/NUnitTestAdapterTests/Fakes/MessageLoggerStub.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ***********************************************************************
// Copyright (c) 2015 Charlie Poole, Terje Sandstrom
// Copyright (c) 2015-2017 Charlie Poole, Terje Sandstrom
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
Expand All @@ -21,15 +21,28 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

namespace NUnit.VisualStudio.TestAdapter.Tests.Fakes
{
public class MessageLoggerStub : IMessageLogger
{
private readonly List<Tuple<TestMessageLevel, string>> messages = new List<Tuple<TestMessageLevel, string>>();
public void SendMessage(TestMessageLevel testMessageLevel, string message)
{
// Do nothing
messages.Add(new Tuple<TestMessageLevel, string>(testMessageLevel, message));
}

public TestMessageLevel LatestTestMessageLevel => messages.Last().Item1;
public string LatestMessage => messages.Last().Item2;

public int Count => messages.Count;

public IEnumerable<Tuple<TestMessageLevel, string>> Messages => messages;
public IEnumerable<Tuple<TestMessageLevel, string>> WarningMessages => messages.Where(o => o.Item1 == TestMessageLevel.Warning);
public IEnumerable<Tuple<TestMessageLevel, string>> ErrorMessages => messages.Where(o => o.Item1 == TestMessageLevel.Error);
}
}
11 changes: 11 additions & 0 deletions src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<OutputType>exe</OutputType>
<OutputTypeEx>exe</OutputTypeEx>
</PropertyGroup>
<ItemGroup>
<Content Include="..\native-assembly\NativeTests.dll" Link="NativeTests.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.7.1" />
Expand All @@ -32,4 +37,10 @@
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

<ItemGroup>
<Compile Update="NavigationDataTests.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
</ItemGroup>
</Project>
88 changes: 76 additions & 12 deletions src/NUnitTestAdapterTests/TestDiscoveryTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ***********************************************************************
// Copyright (c) 2011-2015 Charlie Poole, Terje Sandstrom
// Copyright (c) 2011-2017 Charlie Poole, Terje Sandstrom
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
Expand All @@ -24,10 +24,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using NUnit.Framework;
using Enumerable = System.Linq.Enumerable;

namespace NUnit.VisualStudio.TestAdapter.Tests
{
Expand All @@ -47,7 +49,7 @@ public static IEnumerable<IDiscoveryContext> TestDiscoveryData()
[TestFixtureSource(typeof(TestDiscoveryDataProvider), nameof(TestDiscoveryDataProvider.TestDiscoveryData))]
public class TestDiscoveryTests : ITestCaseDiscoverySink
{
static readonly string MockAssemblyPath =
static readonly string MockAssemblyPath =
Path.Combine(TestContext.CurrentContext.TestDirectory, "mock-assembly.dll");

List<TestCase> TestCases;
Expand All @@ -74,9 +76,9 @@ public void LoadMockassembly()
// the list of test cases sent to the discovery sink
nunittestDiscoverer = ((ITestDiscoverer)new NUnit3TestDiscoverer());
nunittestDiscoverer.DiscoverTests(
new[] { MockAssemblyPath},
_context,
new MessageLoggerStub(),
new[] { MockAssemblyPath },
_context,
new MessageLoggerStub(),
this);
}

Expand All @@ -102,7 +104,7 @@ public void VerifyTestCaseIsFound(string name, string fullName)
public void VerifyNestedTestCaseSourceIsAvailable(string name)
{
var testCase = TestCases.Find(tc => tc.DisplayName == name);

Assert.That(!string.IsNullOrEmpty(testCase.Source));
Assert.Greater(testCase.LineNumber, 0);
}
Expand All @@ -120,29 +122,91 @@ void ITestCaseDiscoverySink.SendTestCase(TestCase discoveredTest)
[Category("TestDiscovery")]
public class EmptyAssemblyDiscoveryTests : ITestCaseDiscoverySink
{
static readonly string EmptyAssemblyPath =
static readonly string EmptyAssemblyPath =
Path.Combine(TestContext.CurrentContext.TestDirectory, "empty-assembly.dll");

private static ITestDiscoverer nunittestDiscoverer;

[TestCaseSource(typeof(TestDiscoveryDataProvider), nameof(TestDiscoveryDataProvider.TestDiscoveryData))]
public void VerifyLoading(IDiscoveryContext context)
{
// Load the NUnit empty-assembly.dll once for this test
nunittestDiscoverer = ((ITestDiscoverer)new NUnit3TestDiscoverer());
nunittestDiscoverer.DiscoverTests(
new[] { EmptyAssemblyPath},
context,
new MessageLoggerStub(),
new[] { EmptyAssemblyPath },
context,
new MessageLoggerStub(),
this);
}

#region ITestCaseDiscoverySink Methods
#region ITestCaseDiscoverySink Methods

void ITestCaseDiscoverySink.SendTestCase(TestCase discoveredTest)
{
}

#endregion
}

[Category("TestDiscovery")]
public class FailuresInDiscovery : ITestCaseDiscoverySink
{
bool testcaseWasSent;


[SetUp]
public void Setup()
{
testcaseWasSent = false;
}

[Test]
public void WhenAssemblyDontExist()
{

#if DEBUG
int noOfMessagesFound = 4; // Start + end , one debug + info
#else
int noOfMessagesFound = 3; // Start + end, + info
#endif
var nunittestDiscoverer = new NUnit3TestDiscoverer();
var context = new FakeDiscoveryContext(null);
var messageLoggerStub = new MessageLoggerStub();
nunittestDiscoverer.DiscoverTests(
new[] { "FileThatDoesntExist.dll" },
context,
messageLoggerStub,
this);
Assert.That(messageLoggerStub.Count, Is.EqualTo(noOfMessagesFound));
Assert.That(messageLoggerStub.LatestTestMessageLevel, Is.EqualTo(TestMessageLevel.Informational));
Assert.That(testcaseWasSent, Is.False);
Assert.That(!messageLoggerStub.ErrorMessages.Any());
}

[Test]
public void WhenAssemblyIsNative()
{
var nunittestDiscoverer = new NUnit3TestDiscoverer();
var context = new FakeDiscoveryContext(null);
var messageLoggerStub = new MessageLoggerStub();
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "NativeTests.dll");
Assert.That(File.Exists(path));
nunittestDiscoverer.DiscoverTests(
new[] { path },
context,
messageLoggerStub,
this);
Assert.That(testcaseWasSent, Is.False);
Assert.That(messageLoggerStub.WarningMessages.Count(), Is.EqualTo(1));
Assert.That(!messageLoggerStub.ErrorMessages.Any());
var warningmsg = messageLoggerStub.WarningMessages.Select(o => o.Item2).Single();
Assert.That(warningmsg, Does.Contain("Assembly not supported"));
}

public void SendTestCase(TestCase discoveredTest)
{
testcaseWasSent = true;
}
}

}
Binary file added src/native-assembly/NativeTests.dll
Binary file not shown.

0 comments on commit 6454201

Please sign in to comment.