Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
        }
}
like image 488
Pitming_Reloaded Avatar asked Dec 28 '22 00:12

Pitming_Reloaded


1 Answers

Try to define it as public instead of protected ie:

[TestInitialize]
public void BeforeAnyTest()
{
    MockRepository = new MockRepository();
}
like image 150
Felice Pollano Avatar answered Jan 10 '23 01:01

Felice Pollano