我使用(或尝试)Silverlight 单元测试。

一切似乎都很好,但是在 [TestInitialize] 之前不会调用带有属性 [TestMethod] 标记的方法。有人知道解决方法吗?

这是一个从未调用过方法 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 而不是 protectedIE:

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

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

10-10 14:52