I want to perform TestCleanup in my unit tests but I need to pass a parameter to the clean-up method. But since the default TestCleanup is called automatically I am not able to pass any parameters to it.
Can somebody please suggest a way to do this?
You could use a test class instance variable to communicate between the setup, test, and cleanup test 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 the CleanUp()
method will run after every unit test, someValue
will be bound to the correct unit test's context.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With