我使用(或尝试) Silverlight单元测试。
看起来一切正常,但是在[TestMethod]之前不会调用用属性[TestInitialize]标记的方法。有人知道解决方法吗?
下面是一个从未调用过BeforeAnyTest方法的示例:
[TestClass]
public class TViewModel
{
protected MockRepository MockRepository { get; set; }
/// <summary>
/// This is strangely not called automatically before any test
/// </summary>
[TestInitialize]
protected void BeforeAnyTest()
{
MockRepository = new MockRepository();
}
[TestMethod]
public void TServerStartupViewModelCtor()
{
//BeforeAnyTest();
var smsa = MockRepository.StrictMock<IServerManagementServiceAgent>();
ServerStartupViewModel ssvm = new ServerStartupViewModel(smsa);
Assert.IsNotNull(ssvm);
}
}发布于 2011-03-03 22:49:22
尝试将其定义为public而不是protected ie:
[TestInitialize]
public void BeforeAnyTest()
{
MockRepository = new MockRepository();
}https://stackoverflow.com/questions/5182033
复制相似问题