I have a batch file that contains multiple tests defined in a similar form below.
vstest.console.exe Test.dll /Settings:"test.runsettings" /Tests:"t1,t2,t3,t4,t5"
The tests run in order from t1 to t5. However, I want to stop vstest if any one of the tests fails. Is this possible using vstest.console.exe?
Btw, the contents of my test.runsettings is
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<MSTest>
<ForcedLegacyMode>true</ForcedLegacyMode>
<KeepExecutorAliveAfterLegacyRun>true</KeepExecutorAliveAfterLegacyRun>
</MSTest>
</RunSettings>
I have checked the Documentation for runsettings, it seems there is no flag/attribute for this case.
If it is an option for you, then you could introduce base class for tests with cleanup, initialize methods and TestContext
property.
In cleanup method you will check if test is failed and by triggering Assert.Fail
in TestInitialize
you don't allow any other test to pass after that.
[TestClass]
public class BaseTest
{
private static bool _failAllTests;
public TestContext TestContext { get; set; }
[TestInitialize]
public void InitializeMethod()
{
if (_failAllTests)
{
Assert.Fail("Fail all tests");
}
}
[TestCleanup]
public void CleanUpMethod()
{
if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed)
{
_failAllTests = true;
}
}
}
[TestClass]
public class UnitTest1 : BaseTest
{
[TestMethod]
public void TestMethod1()
{
Assert.Fail("TestMethod1 failed!");
}
[TestMethod]
public void TestMethod2()
{
Assert.IsTrue(true, "TestMethod2 passed!");
}
}
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