我正在尝试为多个xUnit测试创建一个自定义数据收集器,但是遇到了以下问题:
数据收集:找不到数据收集器'MyDataCollector'
要创建相关的数据收集器,我已按照this文章中的教程进行操作。
我的数据收集器如下:
namespace Test.DataCollectorLibrary
{
[DataCollectorFriendlyName("MyDataCollector")]
[DataCollectorTypeUri("my://new/datacollector")]
public class MyDataCollector : DataCollector
{
int i = 0;
private string tempDirectoryPath = Path.GetTempPath();
private DataCollectionEnvironmentContext context;
private DataCollectionSink dataCollectionSink;
private DataCollectionLogger logger;
public override void Initialize(XmlElement configurationElement,
DataCollectionEvents events,
DataCollectionSink dataSink,
DataCollectionLogger logger,
DataCollectionEnvironmentContext environmentContext)
{
events.TestHostLaunched += this.TestHostLaunched_Handler;
events.SessionStart += this.SessionStarted_Handler;
events.SessionEnd += this.SessionEnded_Handler;
events.TestCaseStart += this.Events_TestCaseStart;
events.TestCaseEnd += this.Events_TestCaseEnd;
this.context = environmentContext ?? throw new ArgumentNullException(nameof(environmentContext));
this.dataCollectionSink = dataSink ?? throw new ArgumentNullException(nameof(dataSink));
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
private void Events_TestCaseStart(object sender, TestCaseStartEventArgs e)
{
this.logger.LogWarning(this.context.SessionDataCollectionContext, "TestCaseStarted " + e.TestCaseName);
this.logger.LogWarning(this.context.SessionDataCollectionContext, "TestCaseStarted " + e.TestElement.FullyQualifiedName);
var filename = Path.Combine(this.tempDirectoryPath, "testcasefilename" + i++ + ".txt");
File.WriteAllText(filename, string.Empty);
this.dataCollectionSink.SendFileAsync(e.Context, filename, true);
}
我正在尝试使用“ dotnet test” 命令从单元测试(包括C#项目文件)所在的目录中运行测试,如下所示:
[单元测试目录]> dotnet测试--collect:“ MyDataCollector” --test-adapter-path“ ../ Test.DataCollectorLibrary / bin / Debug / netcoreapp2.0”
以上命令在PowerShell中运行。在Visual C#解决方案中,单元测试和MyDataCollector都是.NET Core 2.0项目。在上面的“ dotnet测试”命令中,“ ../ Test.DataCollectorLibrary / bin / Debug / netcoreapp2.0”是 Test.DataCollectorLibrary.dll 的路径。
这是什么问题?为什么找不到我的数据收集器?