gpt4 book ai didi

c# - silverlight UnitTesting 不调用 TestInitialize

转载 作者:太空狗 更新时间:2023-10-30 00:21:28 24 4
gpt4 key购买 nike

我使用(或尝试)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);
}
}

最佳答案

尝试将其定义为public 而不是protected即:

[TestInitialize]
public void BeforeAnyTest()
{
MockRepository = new MockRepository();
}

关于c# - silverlight UnitTesting 不调用 TestInitialize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5182033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com