This commit is contained in:
Terje Sandstrom 2014-04-27 11:15:21 +02:00
Родитель 99bf2a4b13 203351709a
Коммит df358a107d
9 изменённых файлов: 146 добавлений и 16 удалений

2
.gitignore поставляемый
Просмотреть файл

@ -15,6 +15,8 @@ build/
[Bb]in/
[Oo]bj/
# Ignore output folder named package
package/
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/

Просмотреть файл

@ -2,6 +2,7 @@
// Copyright (c) 2011 NUnit Software. All rights reserved.
// ****************************************************************
using System;
using System.Reflection;
using System.Runtime.Remoting.Channels;
using NUnit.Util;
@ -15,13 +16,21 @@ namespace NUnit.VisualStudio.TestAdapter
public abstract class NUnitTestAdapter
{
// Our logger used to display messages
protected TestLogger TestLog = new TestLogger();
protected TestLogger TestLog;
// The adapter version
private readonly string adapterVersion;
RegistryCurrentUser Registry { get; set; }
protected bool UseVsKeepEngineRunning { get; private set; }
protected bool UseShallowCopy { get; private set; }
protected int Verbosity { get; private set; }
protected bool RegistryFailure { get; set; }
protected string ErrorMsg
{
get; set;
}
#region Constructor
@ -35,10 +44,23 @@ namespace NUnit.VisualStudio.TestAdapter
ServiceManager.Services.AddService(new ProjectService());
ServiceManager.Services.InitializeServices();
Verbosity = 0;
RegistryFailure = false;
adapterVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
Registry = RegistryCurrentUser.CreateRegistryCurrentUser(@"Software\nunit.org\VSAdapter");
UseVsKeepEngineRunning = Registry.Exist && (Registry.Read<int>("UseVsKeepEngineRunning")==1);
try
{
var registry = RegistryCurrentUser.OpenRegistryCurrentUser(@"Software\nunit.org\VSAdapter");
UseVsKeepEngineRunning = registry.Exist && (registry.Read<int>("UseVsKeepEngineRunning") == 1);
UseShallowCopy = registry.Exist && (registry.Read<int>("UseShallowCopy") == 1);
Verbosity = (registry.Exist) ? registry.Read<int>("Verbosity") : 0;
}
catch (Exception e)
{
RegistryFailure = true;
ErrorMsg = e.ToString();
}
TestLog = new TestLogger(Verbosity);
}
#endregion

Просмотреть файл

@ -20,12 +20,16 @@ namespace NUnit.VisualStudio.TestAdapter
[DefaultExecutorUri(NUnitTestExecutor.ExecutorUri)]
public sealed class NUnitTestDiscoverer : NUnitTestAdapter, ITestDiscoverer
{
#region ITestDiscoverer Members
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink)
{
TestLog.Initialize(messageLogger);
if (RegistryFailure)
{
TestLog.SendErrorMessage(ErrorMsg);
}
Info("discovering tests", "started");
// Ensure any channels registered by other adapters are unregistered
@ -37,16 +41,16 @@ namespace NUnit.VisualStudio.TestAdapter
TestRunner runner = new TestDomain();
TestPackage package = new TestPackage(sourceAssembly);
package.Settings["ShadowCopyFiles"] = false;
package.Settings["ShadowCopyFiles"] = UseShallowCopy;
TestConverter testConverter = null;
try
{
if (runner.Load(package))
{
testConverter = new TestConverter(TestLog, sourceAssembly);
testConverter = new TestConverter(TestLog, sourceAssembly);
int cases = ProcessTestCases(runner.Test, discoverySink, testConverter);
TestLog.SendDebugMessage(string.Format("Discovered {0} test cases", cases));
}
}
else
{
TestLog.NUnitLoadError(sourceAssembly);
@ -70,6 +74,7 @@ namespace NUnit.VisualStudio.TestAdapter
}
catch (Exception ex)
{
TestLog.SendErrorMessage("Exception thrown discovering tests in " + sourceAssembly, ex);
}
finally

Просмотреть файл

@ -37,6 +37,10 @@ namespace NUnit.VisualStudio.TestAdapter
public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
{
TestLog.Initialize(frameworkHandle);
if (RegistryFailure)
{
TestLog.SendErrorMessage(ErrorMsg);
}
Info("executing tests", "started");
try
@ -64,7 +68,7 @@ namespace NUnit.VisualStudio.TestAdapter
}
catch (Exception ex)
{
TestLog.SendErrorMessage("Exception " + ex);
TestLog.SendErrorMessage("Exception thrown executing tests", ex);
}
finally
{
@ -86,6 +90,10 @@ namespace NUnit.VisualStudio.TestAdapter
#endif
TestLog.Initialize(frameworkHandle);
if (RegistryFailure)
{
TestLog.SendErrorMessage(ErrorMsg);
}
var enableShutdown = (UseVsKeepEngineRunning) ? !runContext.KeepAlive : true;
frameworkHandle.EnableShutdownAfterTestRun = enableShutdown;
Debug("executing tests", "EnableShutdown set to " +enableShutdown);

Просмотреть файл

@ -25,6 +25,8 @@ namespace NUnit.VisualStudio.TestAdapter
if (key == null)
return default(T);
var o = key.GetValue(property);
if (o == null)
return default(T);
return (T)o;
}
@ -54,7 +56,7 @@ namespace NUnit.VisualStudio.TestAdapter
private static RegistryCurrentUser currentUser;
public static RegistryCurrentUser CreateRegistryCurrentUser(string key)
public static RegistryCurrentUser OpenRegistryCurrentUser(string key)
{
return currentUser ?? (currentUser = new RegistryCurrentUser(key));
}

Просмотреть файл

@ -236,8 +236,7 @@ namespace NUnit.VisualStudio.TestAdapter
{
// If we can't load it for some reason, we issue a warning
// and won't try to do it again for the assembly.
logger.SendWarningMessage("Unable to reflect on " + sourceAssembly + "\r\nSource data will not be available for some of the tests");
logger.SendWarningMessage(ex.ToString());
logger.SendWarningMessage("Unable to reflect on " + sourceAssembly + "\r\nSource data will not be available for some of the tests",ex);
return null;
}
}

Просмотреть файл

@ -21,6 +21,18 @@ namespace NUnit.VisualStudio.TestAdapter
{
private IMessageLogger messageLogger;
int Verbosity { get; set; }
public TestLogger()
{
Verbosity = 0;
}
public TestLogger(int verbosity)
{
Verbosity = verbosity;
}
public void Initialize(IMessageLogger messageLoggerParam)
{
messageLogger = messageLoggerParam;
@ -53,8 +65,18 @@ namespace NUnit.VisualStudio.TestAdapter
public void SendErrorMessage(string message, Exception ex)
{
SendMessage(TestMessageLevel.Error, message);
SendMessage(TestMessageLevel.Error, ex.ToString());
switch (Verbosity)
{
case 0:
var type = ex.GetType();
SendErrorMessage(string.Format("Exception {0}, {1}",type, message));
break;
default:
SendMessage(TestMessageLevel.Error, message);
SendErrorMessage(ex.ToString());
break;
}
}
public void SendWarningMessage(string message)
@ -62,6 +84,22 @@ namespace NUnit.VisualStudio.TestAdapter
SendMessage(TestMessageLevel.Warning, message);
}
public void SendWarningMessage(string message,Exception ex)
{
switch (Verbosity)
{
case 0:
var type = ex.GetType();
SendMessage(TestMessageLevel.Warning,string.Format("Exception {0}, {1}", type, message));
break;
default:
SendMessage(TestMessageLevel.Warning, message);
SendMessage(TestMessageLevel.Warning,ex.ToString());
break;
}
SendMessage(TestMessageLevel.Warning, message);
}
public void SendInformationalMessage(string message)
{
SendMessage(TestMessageLevel.Informational, message);

Просмотреть файл

@ -78,6 +78,7 @@
<Compile Include="Fakes\FakeFrameworkHandle.cs" />
<Compile Include="Fakes\FakeRunContext.cs" />
<Compile Include="Fakes\FakeRunSettings.cs" />
<Compile Include="RegistryTests.cs" />
<Compile Include="TestConverterTests_StaticHelpers.cs" />
<Compile Include="TestConverterTests.cs" />
<Compile Include="TestDiscoveryTests.cs" />

Просмотреть файл

@ -0,0 +1,53 @@

using NUnit.Framework;
namespace NUnit.VisualStudio.TestAdapter.Tests
{
[TestFixture]
public class RegistryTests
{
[Test]
public void RegistryTestDoesExist()
{
var reg = new RegistryCurrentUser("UseDuringTest");
Assert.That(reg, Is.Not.Null);
}
// [TestCase(true,true)] doesnt do booleans
[TestCase("yep", "yep")]
[TestCase(42, 42)]
// [TestCase('c','c')] doesnt do chars
[Test]
public void RegistryTestWriteReadSimpleTypes<T>(T data, T expected)
{
var reg = new RegistryCurrentUser("UseDuringTest");
reg.Write("SomeData", data);
var wr = reg.Read<T>("SomeData");
Assert.That(wr, Is.EqualTo(expected));
}
[Test]
public void ReadRegistryWithNoData()
{
var reg = new RegistryCurrentUser("UseDuringTest");
var wr = reg.Read<int>("SomeThingNotExisting");
Assert.That(wr,Is.EqualTo(default(int)));
}
[TestCase("UseDuringTest", true)]
[TestCase("ShouldNotBeThere", false)]
[Test]
public void RegistryTestExists(string key, bool expected)
{
var reg = new RegistryCurrentUser(key);
var res = reg.Exist;
Assert.That(res, Is.EqualTo(expected));
}
}
}