问题描述
据我所知,从MSDN,即 ClassInitialize
的标记将尽设置code所有测试,一次,所有测试运行之前的方法。当我有以下删节固定这样的方法,所有的测试失败。当我注释掉,他们再次通过。
[TestClass的]
公共类AuthenticationTests
{
[ClassInitialize]
公共无效SetupAuth()
{
变种X = 0;
}
[测试方法]
公共无效TestRegisterMemberInit()
{
Assert.IsTrue(真正的);
}
}
在 [ClassInitialize]
装饰方法应该是静态的,并采取类型的只有一个参数的TestContext
:
[ClassInitialize]
公共静态无效SetupAuth(的TestContext上下文)
{
变种X = 0;
}
事实上,如果我复制粘贴您的code到一个干净的VS项目中,TestRunner的解释正是在错误信息:
I understand, from MSDN, that ClassInitialize
is to mark a method that will do setup code for all tests, once, before all tests run. When I include such a method in the abridged fixture below, all tests fail. As soon as I comment it out, they pass again.
[TestClass]
public class AuthenticationTests
{
[ClassInitialize]
public void SetupAuth()
{
var x = 0;
}
[TestMethod]
public void TestRegisterMemberInit()
{
Assert.IsTrue(true);
}
}
The [ClassInitialize]
decorated method should be static and take exactly one parameter of type TestContext
:
[ClassInitialize]
public static void SetupAuth(TestContext context)
{
var x = 0;
}
In fact, if I copy-paste your code into a clean VS project, the testrunner explains exactly that in the error message:
这篇关于为什么一个ClassInitialize的装饰方法,让我所有的测试失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!