I want to run TestCleanup in my unit tests, but I need to pass the parameter to the cleanup method. But since TestCleanup is called automatically by default, I cannot pass any parameters to it.
Can anyone suggest a way to do this?
You can use the instance variable of the test class to communicate between installation testing, testing and cleaning methods:
namespace YourNamespace { [TestClass] public class UnitTest1 { private string someValue; [TestMethod] public void TestMethod1() { someValue = "someValue"; } [TestCleanup] public void CleanUp() { // someValue is accessible here. } } }
Since the method CleanUp()will run after each unit test, it someValuewill be bound to the correct unit test context.
CleanUp()
someValue
Hope this helps.
, , , , , , , , - , , , , - .
, .
, , , , ( , , ( , ), ), ( ), , TestFixture, , , , , , , .