silverlight UnitTesting不会调用TestInitialize

Pit*_*ded 4 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);
        }
}
Run Code Online (Sandbox Code Playgroud)

Fel*_*ano 10

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

[TestInitialize]
public void BeforeAnyTest()
{
    MockRepository = new MockRepository();
}
Run Code Online (Sandbox Code Playgroud)