1

We have a large suite of tests with lots of test case functions. Due to running on many platforms/configurations, we now need to add logic to skip inapplicable tests. The "direct" way of doing so would involve adding this to the top of every single test method:

if (!CheckApplicable(/* Input some enum value of test type/platform, etc */))
{
    SkipTest();
    return;
}

I don't really want to paste that everywhere. I would prefer a data-driven look such as attributes if possible. But can an attribute somehow tell it to run code at function start? Any other tricks/techniques, maybe involving reflection, that are worth looking into, that wouldn't be more trouble than they're worth? If not, is there at least some clean way to collapse that type of logic into a single line, while still causing the early return?

Note that we need to exit with a return, not by throwing. Also, we cannot switch test frameworks (we are using TAEF).

Edit: Also note that the outcome of CheckApplicable currently is not known until it is checked at runtime at some point. It is not knowable statically and it cannot depend on the command line due to the peculiarities of a large infrastructure. We could run it once super early though, and somehow reconfigure the test pass then, or just run it before every test case.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
VoidStar
  • 5,241
  • 1
  • 31
  • 45
  • 1
    You usually can hook into the testing framework to have a handler called before each test. What framework is it? – usr Aug 04 '15 at 22:45
  • The framework is TAEF – VoidStar Aug 04 '15 at 22:46
  • If it's nUnit, then it allows to write extension\addin that will generate list of tests that should be executed, and you can generate only needed cases in one place – Sergey Litvinov Aug 04 '15 at 22:46
  • If you are using, try the Explicit attibute. ref http://www.nunit.org/index.php/index.php?p=explicit&r=2.2) – KnightFox Aug 04 '15 at 22:47
  • NUnit actually has attributes that you can use - they allow you to Ignore a test completely, or only ignore it if it is run by a CI server, etc... – stann1 Aug 05 '15 at 08:10

1 Answers1

1

I would encourage to see if "/select" might work for you:

https://msdn.microsoft.com/en-us/library/windows/hardware/hh439686%28v=vs.85%29.aspx

Specifically:

  1. Write a module that will return true/false value, based on your your criteria

  2. Write your script with "/select:", using that dynamic result

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • As I tried to explain in the question, the same command line gets run everywhere due to the infrastructure. The change has to happen within code. – VoidStar Aug 04 '15 at 23:17