We will start using the C # unit test functionality. I have VisualStudio 2008 created unit test code for me. I have few questions about the generated code. Below is the code that I copied from the generated file:
//
//You can use the following additional attributes as you write your tests:
//
//Use ClassInitialize to run code before running the first test in the class
//[ClassInitialize()]
//public static void MyClassInitialize(TestContext testContext)
//{
//}
//
//Use ClassCleanup to run code after all tests in a class have run
//[ClassCleanup()]
//public static void MyClassCleanup()
//{
//}
//
//Use TestInitialize to run code before running each test
//[TestInitialize()]
//public void MyTestInitialize()
//{
//}
//
//Use TestCleanup to run code after each test has run
//[TestCleanup()]
//public void MyTestCleanup()
//{
//}
//
If I need initialization and cleanup methods, do I need to remove these "My" from the method name when I turn them on?
//Use ClassInitialize to run code before running the first test in the class
//[ClassInitialize()]
//public static void MyClassInitialize(TestContext testContext)
//{
//}
I need to call a method "MyClassInitialize"somewhere before starting the first test or it will be called automatically before calling other methods.
Similar questions for the other three methods, are they called automatically in the correct time frame?
source
share