Dotnet test Data Collection problem, “Could not find data collector”












0















I am trying to create a custom data collector for several xUnit tests, but I am running into the following issue:




Data collection: Could not find data collector 'MyDataCollector'




To create the Data Collector in question, I've followed the tutorial in this article.



My Data Collector looks like 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);
}


I am trying to run the tests using the "dotnet test" command, from the directory where the unit tests (including the C# project file) live, like so:




[unit tests directory]>dotnet test --collect:"MyDataCollector" --test-adapter-path "../Test.DataCollectorLibrary/bin/Debug/netcoreapp2.0"




The command above is run in PowerShell. Both the unit tests and the MyDataCollector are .NET Core 2.0 projects, in a Visual C# solution. In the "dotnet test" command above, "../Test.DataCollectorLibrary/bin/Debug/netcoreapp2.0" is the path to Test.DataCollectorLibrary.dll.



Here is the output in the PowerShell console:
enter image description here



What's the problem here? Why is my Data Collector not being found?










share|improve this question



























    0















    I am trying to create a custom data collector for several xUnit tests, but I am running into the following issue:




    Data collection: Could not find data collector 'MyDataCollector'




    To create the Data Collector in question, I've followed the tutorial in this article.



    My Data Collector looks like 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);
    }


    I am trying to run the tests using the "dotnet test" command, from the directory where the unit tests (including the C# project file) live, like so:




    [unit tests directory]>dotnet test --collect:"MyDataCollector" --test-adapter-path "../Test.DataCollectorLibrary/bin/Debug/netcoreapp2.0"




    The command above is run in PowerShell. Both the unit tests and the MyDataCollector are .NET Core 2.0 projects, in a Visual C# solution. In the "dotnet test" command above, "../Test.DataCollectorLibrary/bin/Debug/netcoreapp2.0" is the path to Test.DataCollectorLibrary.dll.



    Here is the output in the PowerShell console:
    enter image description here



    What's the problem here? Why is my Data Collector not being found?










    share|improve this question

























      0












      0








      0








      I am trying to create a custom data collector for several xUnit tests, but I am running into the following issue:




      Data collection: Could not find data collector 'MyDataCollector'




      To create the Data Collector in question, I've followed the tutorial in this article.



      My Data Collector looks like 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);
      }


      I am trying to run the tests using the "dotnet test" command, from the directory where the unit tests (including the C# project file) live, like so:




      [unit tests directory]>dotnet test --collect:"MyDataCollector" --test-adapter-path "../Test.DataCollectorLibrary/bin/Debug/netcoreapp2.0"




      The command above is run in PowerShell. Both the unit tests and the MyDataCollector are .NET Core 2.0 projects, in a Visual C# solution. In the "dotnet test" command above, "../Test.DataCollectorLibrary/bin/Debug/netcoreapp2.0" is the path to Test.DataCollectorLibrary.dll.



      Here is the output in the PowerShell console:
      enter image description here



      What's the problem here? Why is my Data Collector not being found?










      share|improve this question














      I am trying to create a custom data collector for several xUnit tests, but I am running into the following issue:




      Data collection: Could not find data collector 'MyDataCollector'




      To create the Data Collector in question, I've followed the tutorial in this article.



      My Data Collector looks like 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);
      }


      I am trying to run the tests using the "dotnet test" command, from the directory where the unit tests (including the C# project file) live, like so:




      [unit tests directory]>dotnet test --collect:"MyDataCollector" --test-adapter-path "../Test.DataCollectorLibrary/bin/Debug/netcoreapp2.0"




      The command above is run in PowerShell. Both the unit tests and the MyDataCollector are .NET Core 2.0 projects, in a Visual C# solution. In the "dotnet test" command above, "../Test.DataCollectorLibrary/bin/Debug/netcoreapp2.0" is the path to Test.DataCollectorLibrary.dll.



      Here is the output in the PowerShell console:
      enter image description here



      What's the problem here? Why is my Data Collector not being found?







      c# unit-testing xunit data-collection dotnet-test






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 14:49









      lukegflukegf

      89221028




      89221028
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395586%2fdotnet-test-data-collection-problem-could-not-find-data-collector%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395586%2fdotnet-test-data-collection-problem-could-not-find-data-collector%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          ts Property 'filter' does not exist on type '{}'

          mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window