Skip to main content

Consuming IExecutionEvent

Answered

Comments

2 comments

  • Zoltán Tóth

    Take a look at the code of TestThreadExecutionEventPublisher. You have to add the listener manually. So you have to resolve an ITestThreadExecutionEventPublisher from the thread container and call AddListener or AddHandler to hook into the execution events of the test thread.

    0
  • Dean Tessman

    Thanks Zoltán Tóth, that worked perfectly. I'll document here for future reference by others:

        public class CustomRunner : IRuntimePlugin
    {
    ........
    public void Initialize(RuntimePluginEvents runtimePluginEvents,
    RuntimePluginParameters runtimePluginParameters,
    UnitTestProviderConfiguration unitTestProviderConfiguration)
    {
    runtimePluginEvents.CustomizeTestThreadDependencies += CustomizeTestThreadDependencies;
    }

    private void CustomizeTestThreadDependencies(Object sender, CustomizeTestThreadDependenciesEventArgs e)
    {
    if (e.ObjectContainer.IsRegistered<ITestThreadExecutionEventPublisher>())
    {
    var publisher = e.ObjectContainer.Resolve<ITestThreadExecutionEventPublisher>();
    publisher.AddListener(new CustomListener());
    }
    }
    }

    public class CustomListener : IExecutionEventListener
    {
    public void OnEvent(IExecutionEvent executionEvent)
    {
    switch (executionEvent)
    {
    case TestRunStartedEvent startEvent:
    {
    // do stuff
    break;
    }
    case FeatureStartedEvent startEvent:
    {
    // do other stuff
    break;
    }
    case ScenarioStartedEvent startEvent:
    {
    // hey look - more stuff!
    break;
    }
    }
    // etc.
    }
    }
    0

Please sign in to leave a comment.

Powered by Zendesk