Answered by:
TestInitialize broken in Visual Studio 2012 Update1
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
- Edited by Xiaoguang Qiao Wednesday, December 12, 2012 12:30 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
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. -
-
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. -
-
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- Proposed as answer by Fernando DeSantos Tuesday, December 18, 2012 11:50 PM
-
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
-
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