c# - Accessing CurrentTestOutcome in ClassCleanup? -
Using C # 4.0 I have a unit test where I need to create a temporary database during class initialization Used:
[Class initial ()] Public static zero MyClassInitialize (TestContext testContext) {// Create database! } [Class cleanup ()] public static zero MyClassCleanup () {// Remove database IF CurrentTestOutcome == UnitTestOutcome.Passed} Q: How can I read CurrentTestOutcome My ClassCleanup method by value
I Suggest that you create a static flag, which you can access from your MyClassCleanup and when you receive an error, you can set it during your cleaning test, not in your class Something like the following: [test class] public class mystages {static bool _testFailed; [Start the class ()] Public static zero MyClassInitialize (TestContext testContext) {// Create database! _testFailed = false; } [Class cleanup ()] public static micelluscleanup () {if (_testFailed == wrong) {// remove database} IF CurrentTestOutcome == UnitTestOutcome.Passed}} [TestCleanup ()] Public Zero MyTestCleanup () {if (TestContext.CurrentTestOutcome ! = UnitTestOutcome.Passed) {_testFailed = true; }} Public TestContext TestContext {get; Set; }} I am suggesting the above approach because I understand that referring to CurrentTestOutcome in cleaning your class does not really really happen much This will only be involved in running the last test status, not the result of all tests in the classroom.
Comments
Post a Comment