Do you ever feel that your testing is a sort of tautology (A is true because, well, A is true)? If so, how do you put in place checks and balances to avoid this?
Recently I've been working on a test suite that validates the data and behavior belonging to a number of big ugly complex objects (hence forth called BUCOs). These objects are built up of smaller pieces and there are unit tests for each of these smaller pieces.
To make my testing easier I've try to build up a repository of pre-built pre-tested objects, stored in Perl constants. Then I compose the BUCOs from these smaller (already tested objects). This works nicely most of the time because the BUCOs are usually just composite objects and the constructor takes the components as parameters.
However, not all BUCO's can be built this way. Some of my BUCOs interact with the file system or a database or some other major system. In each of these cases my practice is to create a mock environment. For example, if I need to see how a BUCO interacts with a directory tree, I might use File::Temp to create such a tree complete with files and subdirectories and any other goodies I need in this mock environment. The BUCO constructor often needs some sort of identifiers from this mock environment. The expectations also need to be derived from this environment.
When I build test objects I like to hard code as much as possible of my expectation set. Human error can be easily introduced when expectations are hard coded, but at least the expectations are out there in the open to be inspected. However, when constructor inputs and expectations are drawn from a mock object, then hard coding isn't always an option. For example, if an expectation concerns a fully qualified directory path and the root of that directory is a randomly generated temp file name, then one has no choice but to generate the fully qualified path from the temp root and a relative path.
The problem I repeatedly run into is this: oftentimes the code used to extract an expectation from the mock environment looks suspiciously like the very code I'm testing! I try various things to avoid a tautology, but I don't have a lot of confidence in any of them:
So what safeguards do you put in place to avoid tautologies when testing BUCOs? Is there an approach I'm missing? Are some things just untestable? I would be most grateful for the experiences and opinions of my fellow monks.
Thank you in advance, beth
In reply to How does one avoid tautologies in testing? by ELISHEVA
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |