I can successfully run the VS unit tests from the command line (and hence from the build on the build machine).
VSTest.Console.EXE "MyTest.dll" /logger:trx /platform:x64 /inIsolation
I can also filter out any required tests that I don't want to execute on a certain environment with /TestCaseFilter
option:
VSTest.Console.EXE "MyTest.dll" /TestCaseFilter:Name!=Verify_DigitallySigned
This is needed to not to run "check if digitally signed" test(s).
This way I can filter out the required set of test case/s.
However, what I want is to let the unit test know if certain tests (asserts) are not required. For example passing a "/DontTestSigning"
argument. This way the unit tests (written in C++ or C#) would see such parameter/option, and would not do additional asserts, thus preventing the build failures on not-real production builds (such as on PR builds).
I see that there is /testsettings
option with VSTest.Console.exe (and with MSTest.exe also), but I am not sure how (IF) that can be applied and letting the actual test functions to know about some "dont-do" option.
Basically you should favour to have only a single Assert
within your test, so that every tests checks for one single thing.
So what you have is similar to this, I suppose:
[Test]
public void MyTest()
{
Assert.That(...);
Assert.That(...);
Assert.That(...);
}
When you want to exclude e.g. the second Assert
, you have of course to provide some functionality in your code to execute or not to execute those lines, e.g.:
public void MyTest()
{
Assert.That(...);
if(executeSecondAssert)
Assert.That(...);
Assert.That(...);
}
You can introduce some compile-switch that sets the value for the above bool-flag:
#if(EXECUTE_ASSERT)
bool executeSecondAssert = true;
#else
bool executeSecondAssert = false;
and now provide that compile-switch via an environment-variable.
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