Mid Testing

How do you use the [TestInitialize] and [TestCleanup] attributes?

  • [TestInitialize] runs code before each test method to set up prerequisites.
  • [TestCleanup] runs after each test method to clean up resources.

[TestInitialize]

public void Setup() { /* setup code */ }

[TestCleanup]

public void Cleanup() { /* cleanup code */ }

More from C# Programming Tutorial

All questions for this course