mardi 4 août 2015

In C#, is there any magic way to check+early-return from ~thousand test case functions without pasting that code everywhere?

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.

Aucun commentaire:

Enregistrer un commentaire