Skip to content

Instantly share code, notes, and snippets.

@diegocaxito
Created January 16, 2012 11:37
Show Gist options
  • Save diegocaxito/1620457 to your computer and use it in GitHub Desktop.
Save diegocaxito/1620457 to your computer and use it in GitHub Desktop.
Global test Initialize Method for MSTest
/*
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