silverlight UnitTesting不会调用TestInitialize

时间:2011-03-03 14:29:15

标签: c# unit-testing silverlight-4.0

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

一切似乎都没问题但是在[TestInitialize]之前没有调用使用属性[TestMethod]进行调查的方法。有人知道解决方法吗?

这是一个从未调用Method 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);
        }
}

1 个答案:

答案 0 :(得分:10)

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

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