Created
January 16, 2012 11:37
-
-
Save diegocaxito/1620457 to your computer and use it in GitHub Desktop.
Global test Initialize Method for MSTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
With MSTest aren’t possible use ClassInitialize and ClassCleanup methods with inheritance. | |
To use methods that initialize and finalize with Test Class you need to use Constructor and Destructor of a base class like in sample. | |
*/ | |
using System; | |
namespace GlobalInitializeDemo | |
{ | |
public abstract class MyBaseTestClass : IDisposable | |
{ | |
protected MyCommonClass common; | |
protected MyBaseClass() | |
{ | |
common = new Commom(); | |
common.Init(); | |
} | |
public void Dispose() | |
{ | |
common.Finalize(); | |
} | |
} | |
[TestClass] | |
public class MyTestClass : MyBaseTestClass | |
{ | |
[TestMethod] | |
public void MyTestMethod() | |
{ | |
var context = common.GetContext(); | |
... | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment