I have been searching for some time for ways to get the error message in NUnit. So far, I found some classes that use IAddin and EventListener to get the message, but it didn't work. I based this code on this links:
I added the code to the project, but nothing is being recorded, or being done when the tests failed. I read that I have to add the dll to some "NUnit\addins\" folder, but I couldn't find any addin folder with this "addins".
I don't know what I'm missing, can someone help me?
Below is the code that I used:
using System;
using System.IO;
using NUnit.Core;
using NUnit.Core.Extensibility;
namespace Test
{
[NUnitAddinAttribute(Type = ExtensionType.Core,
Name = "Database Addin",
Description = "Writes test results to the database.")]
public class MyNunitExtension : IAddin, EventListener
{
public bool Install(IExtensionHost host)
{
IExtensionPoint listeners = host.GetExtensionPoint("EventListeners");
if (listeners == null)
return false;
listeners.Install(this);
return true;
}
public void RunStarted(string name, int testCount) { }
public void RunFinished(TestResult result) { }
public void RunFinished(Exception exception) { }
public void TestStarted(TestName testName) { }
public void TestFinished(TestResult result)
{
using (var arq = File.Open(@"C:\Temp\Log.txt", FileMode.Append))
using (var writer = new StreamWriter(arq))
{
var message = string.Format("[{0:s}] [{1}] {2}", DateTime.Now,
result.ResultState, result.Name);
writer.WriteLine(message);
var isFailure =
result.ResultState == ResultState.Error ||
result.ResultState == ResultState.Failure;
if (isFailure)
{
writer.WriteLine(result.Message);
}
}
}
public void SuiteStarted(TestName testName) { }
public void SuiteFinished(TestResult result) { }
public void UnhandledException(Exception exception) { }
public void TestOutput(TestOutput testOutput) { }
}
}
Aucun commentaire:
Enregistrer un commentaire