This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
Custom DataCollector not found #248
Open
Description
openedon Apr 27, 2021
Hi there,
I'm trying to add a custom log collector to our tests and I'm not able to get the collector recognized. It very simply just collects failed test cases and prints them out at the end.
I've followed the examples found over at analyize.md and have the following:
// ./LogCollector/LogCollector.cs
using System.Collections.Generic;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
namespace LogCollector
{
[DataCollectorFriendlyName("LogCollector")]
[DataCollectorTypeUri("datacollector://LogCollector")]
public class LogCollector : DataCollector
{
private readonly List<TestCase> _failedTests = new List<TestCase>();
private DataCollectionLogger _logger;
public override void Initialize(XmlElement configurationElement, DataCollectionEvents events,
DataCollectionSink dataSink,
DataCollectionLogger logger, DataCollectionEnvironmentContext environmentContext)
{
events.TestCaseEnd += TestCaseEnd_Handler;
events.SessionEnd += SessionEnd_Handler;
_logger = logger;
}
private void SessionEnd_Handler(object? sender, SessionEndEventArgs e)
{
_failedTests.ForEach(testCase =>
_logger.LogError(new DataCollectionContext(testCase), testCase.FullyQualifiedName)
);
}
private void TestCaseEnd_Handler(object? sender, TestCaseEndEventArgs testCaseEndEventArgs)
{
if (testCaseEndEventArgs.TestOutcome == TestOutcome.Failed)
{
_failedTests.Add(testCaseEndEventArgs.TestElement);
}
}
}
}
and my .runsettings
file looks like this:
<!-- ./.runsettings -->
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<RunConfiguration>
<TestAdaptersPaths>./LogCollector/LogCollector.cs</TestAdaptersPaths>
</RunConfiguration>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="LogCollector" uri="datacollector://LogCollector"/>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
When I run the tests with dotnet test --collector LogCollector
I'm faced with the error:
Data collection : Unable to find a datacollector with friendly name 'LogCollector'.
Data collection : Could not find data collector 'LogCollector'
Does anyone have any insight into how I can get the data collector to be picked up by the test runner?
Thanks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels