ClassInitialize attribute not used in a based class - by ShadoFil

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 687481 Comments
Status Closed Workarounds
Type Bug Repros 3
Opened 9/7/2011 1:56:50 AM
Access Restriction Public



I added these method in a TestBase class :

public static void InitializBeforeAllTests()

But when I run in Debug an unit test "Test1()" :

public class TestMapping : TestBase
    public void Test1()

the TestBase.InitializeBeforeAllTests() method is never called.

Thank you
Sign in to post a comment.
Posted by PaulyK on 12/29/2011 at 10:07 AM
yes, but why not just implement Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter such that it calls any static methods attributed with ClassInitialize or ClassCleanup in a base class, as well as the derived class? this would be far more useful, and obviate the need to create a test class extension for such a common case... btw, relying on the derived class implementation to manually call the base class equivalents is too fragile...
Posted by ShadoFil on 9/12/2011 at 7:26 AM
Thank you for your answer.

This precision is not very clear in the documentation.

It's a pity we can't move the ClassInitialize in a based class.
We already have 800 unit tests in start of the projet. So we must to manually add a same ClassInitialize method in all test class, while we could use inheritance. And, each time we create a new test class, we need add a Class initialize we is identical at others tests. It is not productive.

It will be useful for productivity to have this possibility.
Posted by Microsoft on 9/12/2011 at 12:41 AM
Thank you for your feedback. We looked at the reported problem and found that the behaviour which you observed is expected.

The method having ClassInitialize attribute should not be declared in the base class, rather it should be declared in the class that contains the tests.

To read more about classInitialize, please have a look at the msdn documentation.

Visual Studio Product team
Posted by MS-Moderator01 on 9/7/2011 at 2:42 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(
Posted by MS-Moderator08 [Feedback Moderator] on 9/7/2011 at 2:15 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.