locked
TestInitialize broken in Visual Studio 2012 Update1 RRS feed

  • Question

  • When I installed Visual Studio 2012 Update1, I found a breaking change in execution order of

    See code below

        [TestClass]
        public class UnitTest1 : Base3
        {
            [TestMethod]
            public void TestMethod1()
            {
            }
    
            [TestInitialize]
            public void Init()
            {
                Console.WriteLine("In test class");
            }
        }
    
        [TestClass]
        public class Base3 : Base2
        {
            [TestInitialize]
            public void InitBase3()
            {
                Console.WriteLine("In base3");
            }
        }
    
        [TestClass]
        public class Base2 : Base1
        {
            [TestInitialize]
            public void InitBase2()
            {
                Console.WriteLine("In base2");
            }
        }

    Before Update1, it generates

    In base1
    In base2
    In base3
    In test class,

    With Updaet1, it generates

    In base3
    In base2
    In base1
    In test class.

    I think it a bug in Update1 because in most case initialization should happen in base class first. For example, class initialization. Could someone confirm if it's a bug and let me know if there is walkaround.


    Have fun with Reporting Service


    Wednesday, December 12, 2012 12:25 PM

Answers

  • The fix has already been committed to our code and will be available in the next public release of Visual Studio 2012.  You would be able to get this fix in the next available CTP for Quarterly Update 2. There are no dates available as yet.


    Allen Mathias
    Senior Dev Lead @ Microsoft

    • Marked as answer by Xiaoguang Qiao Thursday, December 20, 2012 8:44 AM
    Wednesday, December 19, 2012 5:18 PM

All replies

  • Hello Xiaoguang,

    Thank you for your post.

    I have reproduced your scenario before and after installing VS2012 Update 1 on the same machine. I get the same result below.

    In base1

    In base2

    In base2

    In test class

    Also I have tried the same scenario on another machine with VS2012 Update1, and get the same result.

    I suggest that you try the same scenario on another machine with VS2012 Update1 to check the result.

    Please update the result on the thread once you have tried it.

    Thank you for your post.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 13, 2012 6:36 AM
  • Hi

    Could you please confirm the version of VS (premium/ultimate) and the OS that you are working on?


    Thank You
    Allen Mathias

    Thursday, December 13, 2012 1:04 PM
  • Thank Allen for the friendly help.

    Hello Xiaoguang,

    Both of my repro operations are performed with Visual Studio 2012 Ultimate RTM version and Windows 7 operation system.

    As Allen said, you can provide us your environment information so that we can repro it better.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 14, 2012 2:01 AM
  • I can repro it on several machines. All of them are Windows 8 machine.

    I can repro it either in VS Ultimate 2012 Update1 (11.0.51106.01) + .NET framework 4.5.50709 or test agent 2012 Update1.


    Have fun with Reporting Service

    Friday, December 14, 2012 6:29 AM
  • Hi Xiaoguang

    I can confirm that this a bug in Update1. We are tracking this internally and will have a fix out in the subsequent refresh.

    For now the workaround is to explicitly call Base.Initialize from your TestInitialize function ie adding in code to handle the same.

    Thank you for reporting this issue.


    Thank You
    Allen Mathias
    Senior Dev Lead - Unit Testing, Code Coverage and Test Infra
    Microsoft

    Friday, December 14, 2012 6:58 AM
  • Hi Allan,

    It's not a easy fix for us, because we don't leverage virtual method to do initialization. We have test base for each feature, and some sub feature is derived from top level test base. Lots of code change are required.

    Could you let me know rough schedule of the fix, so I can decide whether to downgrade VS 2012 without Update1 or make code change from now?


    Have fun with Reporting Service

    Friday, December 14, 2012 10:16 AM
  • The fix has already been committed to our code and will be available in the next public release of Visual Studio 2012.  You would be able to get this fix in the next available CTP for Quarterly Update 2. There are no dates available as yet.


    Allen Mathias
    Senior Dev Lead @ Microsoft

    • Marked as answer by Xiaoguang Qiao Thursday, December 20, 2012 8:44 AM
    Wednesday, December 19, 2012 5:18 PM