A couple of commenters on my previous post have taken issue with my use of interfaces to form contracts between test cases and the test framework, rather than using simple virtual methods and inheritance as found in DUnit. I thought it would be interesting to illustrate why I went down this route.
It is suggested that using inheritance means that discovering the methods required to be implemented to support Setup/TearDown in DUnit is simpler than having to know the required interface name and then having to lookup the method signature involved, as in the case of Smoketest.
This of course assumes that documentation either does not exist or is being wilfully ignored.
First of all, the interfaces in Smoketest are designed to be highly memorable. They read as a natural description of a behaviour that a test case class follows.
Where a test case has some project setup to perform it states “I Setup (the) Project“. If it has some setup to perform specific to the test case “I Setup (this) Test Case“. And so on.
So remembering the interface name really shouldn’t be hard, since it describes what you wish to achieve. Whether you intuit the interface name, select it from the fairly short list of interfaces offered by IDE Code Completion, the chances are you will only have to look it up once.
The compiler then ensures that the contract is fulfilled.
So let’s assume you at least know the interface involved and look at the impact that using the interface has on finding the method(s) required, as compared to finding the method from the list of inherited methods.
First, let’s look at what the IDE offers when we invoke Code Completion in the class declaration of a DUnit test case.
I made my suggestion list popup as big as I possibly could, but they aren’t on even the first page of this greatly enlarged list so scrolling down to the next complete page of suggestions ….
Aha – there they are. Setup and Teardown. Look carefully, you will see them eventually.
Of course, to find them you have to already know what you are looking for since they are simply listed alphabetically among all the other methods that you have no intention of implementing yourself.
I don’t see any methods for performing per-test or project-wide setup/teardown though, so I am not entirely sure of the context in which Setup and Teardown operate. I guess I’ll have to read the documentation after all.
Now let’s look at the same Code Completion offering for a Smoketest test case class declaration:
Well, would you look at that. The methods introduced by my specified interface contracts (in this case, that I will provide a name for the case and that I perform some test case setup), are put front and centre.
Now, without the interfaces declared on the class, I would see no such methods at all. But is this really a problem ? I don’t think so. The list of available methods is itself much shorter and the complete lack of any setup/cleanup methods will itself remind me that I have to form my contract with the framework first.
And I then get to choose which contract – setting up specific test methods, the test case or project wide setup (and/or attendant cleanup).
On that note, issue has also been taken with the use of “Cleanup” rather than “TearDown” in the method and interface names. This was deliberate. TearDown has a finality about it that seemed to be most often not appropriate.
Take for example the JSON test case which performs some cleanup after every test method by clearing a JSON object in preparation for the next test method. This really isn’t “tearing anything down”. It really is just “cleaning up”.
Sometimes your cleanup will involve completely destroying some artefacts used/created during testing, but this is just one extreme form of cleanup.
When the house-work needs doing, do you tear down your house or do you clean it up ?
Even tearing down the house, if/when it ever becomes necessary, is only what you do in order to “clean” the site, in readiness for a new house to be built.
TearDown may appeal to some people’s sense of the dramatic, but other than that it is actually a very poor choice of name imho.
I didn’t create Smoketest in order to simply create a plug-compatible alternative to DUnit. I didn’t even create it as a “competitor” for DUnit. I created it for myself precisely because I didn’t and don’t like the way DUnit works.
And because DUnit didn’t and doesn’t do some things that I wanted and needed (see my next post).
I simply choose now to share it.
If you do like the way DUnit works you are of course more than welcome to continue using it, but don’t expect Smoketest to conform to any expectations you might bring from that other framework.
Comments are now closed.