【问题标题】:Could not find vstest test logger with URI or FriendlyName找不到带有 URI 或 FriendlyName 的 vstest 测试记录器
【发布时间】:2018-03-20 23:01:41
【问题描述】:

我正在尝试按照这篇文章Writing loggers for command line test runner vstest.console.exe 实现我的自定义vstest 记录器,我在VS 解决方案中有3 个项目。

类库1 仅包含一个示例 Service 类。

public class Service
    {
        public int GetDocumentNumber(Guid documentId)
        {
            if (documentId == Guid.Empty)
            {
                throw new ArgumentException("Document id is empty guid.");
            }

            return 178;
        }
    }

SimpleLoggerVSTest(类库) 仅包含一个类。 ITestLogger 是来自Microsoft.VisualStudio.TestPlatform.ObjectModel 的接口。

[ExtensionUri("logger://SimpleConsoleLogger/v1")] /// Uri used to uniquely identify the console logger. 
[FriendlyName("SimpleLogger")] /// Alternate user friendly string to uniquely identify the logger.
        public class SimpleLogger : ITestLogger
        {
            public void Initialize(TestLoggerEvents events, string testRunDirectory)
            {
                Console.WriteLine("++++ Initialize ++++");
            }
        }

UnitTestProject 仅包含一个测试类。

[TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            // Arrange 
            Guid documentId = Guid.NewGuid();
            Service service = new Service();

            // Act
            var res = service.GetDocumentNumber(documentId);

            // Assert
            Assert.AreEqual(res, 178);
        }

        [TestMethod]
        public void TestMethod2()
        {
            // Arrange 
            Guid documentId = Guid.Empty;
            Service service = new Service();

            // Act
            var res = service.GetDocumentNumber(documentId);

            // Assert
            Assert.AreEqual(res, 178);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestMethod3()
        {
            // Arrange 
            Guid documentId = Guid.Empty;
            Service service = new Service();

            // Act
            service.GetDocumentNumber(documentId);
        }
    }

UnitTestProject 引用了第一个 ClassLibrarySimpleLoggerVSTest

我厌倦了在Developer Command Prompt for VS 2017中执行以下命令。

cd C:\Users\User\source\repos\Solution2\UnitTestProject1\bin\Debug
vstest.console.exe UnitTestProject1.dll /TestAdapterPath:. /Logger:SimpleLogger

我收到以下错误:

找不到具有 URI 或 FriendlyName 'SimpleLogger' 的测试记录器。

我做错了什么?你能帮帮我吗?

编辑:所以,我听说它可能是由旧版本的 Visual Studio 引起的。但我有 15.6.3。

【问题讨论】:

  • @haim770 我评论了ExtensionUri 属性并使用了小写命令。它没有帮助。我遇到了同样的错误。

标签: c# vstest


【解决方案1】:

确保您的 SimpleLogger 类存在于名称以 testlogger.dll 结尾的程序集中。

【讨论】:

  • 背后的逻辑是什么?我应该调用我的 dll something_testlogger.dll 对吗?或者您的回答是关于其他事情(我不太清楚)?谢谢!
  • vstest.console.exe 仅在以 testlogger.dll 结尾的程序集中查找 ITestLogger 实现。是的,它应该是 somethig_testlogger.dll。
猜你喜欢
  • 2021-10-03
  • 2022-08-22
  • 1970-01-01
  • 2017-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2016-07-29
相关资源
最近更新 更多