【发布时间】: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 引用了第一个 ClassLibrary 和 SimpleLoggerVSTest。
我厌倦了在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属性并使用了小写命令。它没有帮助。我遇到了同样的错误。