C# unit test code questions

Posted by 5YrsLaterDBA on Stack Overflow See other posts from Stack Overflow or by 5YrsLaterDBA
Published on 2010-04-26T14:06:13Z Indexed on 2010/04/26 14:13 UTC
Read the original article Hit count: 488

Filed under:
|

We start use C# build-in unit test functionality. I have VisualStudio 2008 created unit test code for me. I have few question above the generated code. Following are code I copied from the generated file:

  #region Additional test attributes
  // 
  //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()
  //{
  //}
  //
  #endregion

If I need the initialize and cleanup methods, do I need to remove those "My" from the method name when I enable them?

  //Use ClassInitialize to run code before running the first test in the class
  //[ClassInitialize()]
  //public static void MyClassInitialize(TestContext testContext)
  //{
  //}

Do I need to call the "MyClassInitialize" method somewhere before running the first test or it will be called automatically before other methods are called.

Similar questions for other three methods, are they called automatically at right time frame?

© Stack Overflow or respective owner

Related posts about c#

Related posts about unit-testing