inline testing versus unit testing
Posted: Thu Jan 17, 2008 3:41 pm
When I first started in C I was quickly introduced to the assert macro...when I made the transition into Windows development and started using MFC the ASSERT macro was a quick replacement.
These are handy little (debug mode only) macros which you use to assert the pre and post states of a methods under test.
This was my style of testing until I switched to PHP because there is no native ASSERT macro which is removed during release. I started gaining interest in TDD and most recently BDD to basically accomplish the same effect with the following advantages:
Opinions, input, etc???
Cheers
These are handy little (debug mode only) macros which you use to assert the pre and post states of a methods under test.
Code: Select all
function doSomething($object, $value)
{
ASSERT($object instanceOf MyClass);
ASSERT($value > 0 && <= 10);
// ...
$result = $stuff_above;
ASSERT($result != 15);
return $result;
}
- Externalizing your tests makes for a form of 'hot to use' API documentation
- Speeds up the production code by removing test-centric code and also clears the production code. Lots of testing code leads to obfuscated source
- Externalizing tests allows arbitrarty number of test input and output. Making it easy to add or remove additional tests without touching source code
- Portability & Reuse. The odd chance you have a similar API in the future, you possibly reuse your tests
- Frameworks for automation, generating nice displays, etc
Opinions, input, etc???
Cheers