jeudi 25 février 2021

How to implement NUnit's NUnit.Engine.ITestEventListener

I would like to use NUnit.Engine.ITestEventListener within my test solution. Specifically I would be looking for end of the run <test-run...>.

I implemented the interface ITestEventListener within C# code within my test csproj. I set a break point within the interface. Within Visual Studio, I began debugging tests; never hit the break point. I then wondered if this is a NUnit Engine thing and MSTest knows nothing of it. Am I correct that MSTest will never hit my breakpoint with my class that implements ITestEventListener?

Alright lets try something else like writing out to the console log by using nunit3-console.exe to run the tests. My output within the interface never wrote a thing - everything else wrote out properly. So, what am I doing incorrectly?

using System;
using NUnit.Engine;
using NUnit.Engine.Extensibility;

namespace Learning.NUnitInterface
{
    [Extension]
    public class MyTestListener : ITestEventListener
    {
        public void OnTestEvent(string report)
        {
            Console.WriteLine("Hello there, here is your data: ");
            Console.WriteLine(report);
        }
    }
}
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="log4net" Version="2.0.12" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
    <PackageReference Include="NUnit" Version="3.13.1" />
    <PackageReference Include="NUnit.Console" Version="3.12.0" />
    <PackageReference Include="NUnit.ConsoleRunner" Version="3.12.0" />
    <PackageReference Include="NUnit.Engine" Version="3.12.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
  </ItemGroup>

</Project>

Aucun commentaire:

Enregistrer un commentaire