Pitming_Reloaded
Pitming_Reloaded

Reputation: 559

silverlight UnitTesting doesn't call TestInitialize

I use (or try) the Silverlight unittesting.

everything seems alright but the methods taged with attribute [TestInitialize] are not called before the [TestMethod]. Anyone knows a workaround ?

here is a sample where Method BeforeAnyTest is never called:

    [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);
        }
}

Upvotes: 4

Views: 451

Answers (1)

Felice Pollano
Felice Pollano

Reputation: 33272

Try to define it as public instead of protected ie:

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

Upvotes: 10

Related Questions