Hi Martin,
Yeah, google test has "death tests" and I consider them a very bad idea. Like you, I've been thinking about this one for quite a while till I was over the fence and very firm in the "bad idea" camp :)
There were a couple of things that pushed me in the "bad idea" camp:
- Having tests that should crash sounds like a bad idea…
- Crashing seems to be just like any 3rd party behavior (interesting thought, but very important)
- These tests are fragile and slow and not very portable.
For checking assertions, it is better to record the assertions and use a test plugin. Someone submitted an assert checking library earlier and we've not yet integrated that.
For crashing. I've test-droven some crashing behaviour in the CppUTest memory allocation framework. To copy some code from there:
static void crashMethod()
{
cpputestHasCrashed = true;
}
void setup()
{
UtestShell::setCrashMethod(crashMethod);
cpputestHasCrashed = false;
}
TEST(MemoryLeakWarningGlobalDetectorTest, crashOnLeakWithOperatorNewArray)
{
crash_on_allocation_number(1);
char* memory = new char;
CHECK(cpputestHasCrashed);
delete memory;
}
I've simply stubbed out the crashing part ;P
The only LOC that is really untested is:
static void defaultCrashMethod()
{
UtestShell* ptr = (UtestShell*) 0x0; ptr->countTests();
}
I figured, you always want to be able to stub out the crashing part and thus then death tests are always useless. It is just poor test design.
Hope this pushes you off that fence :P
Bas
> --
> You received this message because you are subscribed to the Google Groups "cpputest" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
cpputest+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>