我正在尝试扩展 .NET TestClass
。我发现我需要扩展以下抽象类:TestClassExtensionAttribute
和TestExtensionExecution
. TestExtensionExecution
还需要我实现一个ITestMethodInvoker
. 我已经完成了以下操作,但是当我运行一个测试方法时,我的断点都没有被命中(无论是在测试中还是在扩展中),这意味着测试类永远不会到达我的扩展并且显然在更早的时候失败了。有人可以指出我所缺少的或如何扩展的工作示例 TestClass
吗?
扩大:
class CoreTestClass : TestClassExtensionAttribute
{
public override Uri ExtensionId
{
get { throw new NotImplementedException(); }
}
public override TestExtensionExecution GetExecution()
{
return new TestCore();
}
}
class TestCore: TestExtensionExecution
{
public override ITestMethodInvoker CreateTestMethodInvoker(TestMethodInvokerContext context)
{
return new AnalysisTestMethodInvoker();
}
public override void Dispose()
{
}
public override void Initialize(TestExecution execution)
{
execution.OnTestStopping += execution_OnTestStopping;
}
void execution_OnTestStopping(object sender, OnTestStoppingEventArgs e)
{
throw new NotImplementedException();
}
}
class AnalysisTestMethodInvoker : ITestMethodInvoker
{
public TestMethodInvokerResult Invoke(params object[] parameters)
{
throw new NotImplementedException();
}
}
测试:
[CoreTestClass]
public class HomeControllerTest
{
[TestMethod]
public void Index()
{
// Arrange
HomeController controller = new HomeController();
// Act
ViewResult result = controller.Index() as ViewResult;
// Assert
Assert.AreEqual("Modify this template to jump-start your ASP.NET MVC application.", result.ViewBag.Message);
}
}