Skip to content

Contract Checks: Once and Only Once for Unit Testing (Part I)

ADMIN | 01-02-2011

My instinct is that there’s something wrong if one needs to spend a large fraction of ones architectural effort on code which is not part of the shipped product

Hexagon pattern 1

In her post that started this thread, Stef mentioned Meszaros' book on xUnit.  My reaction when I bought the book was a bit different from hers; it was what I would now describe as a smell.  My instinct was that there’s something wrong if one needs to spend a large fraction of one’s architectural effort on code which is not part of the shipped product.

 

Note that I am not saying that effort spent on testing and test automation is valueless if the tests aren’t part of the shipped product.  Spatial has been running hundreds of thousands of (scripted) ACIS tests every night since before I joined the company oh so many years ago; our test suite is one of our most valuable pieces of IP.  Instead, my instinct was that that typical usage of what Meszaros calls the "Four-Phase Testpattern probably violates some core OO design principle, which in turn requires expending a lot of (architectural) cleverness to manage the resulting complexity. 

 

For reference, let me explicitly write down my (simplified) version of the four phases:

1.      Set up the input data (objects) and owning object(s) for the method(s) to be tested.

2.      Execute the method(s).

3.      Perform validation tests (usually a set of assertions) on the outputs (including the owning object(s)) to check the result.

4.      Return the xUnit application to its (hopefully) original “clean” state.

 

My original thought was that construction of data objects during setup (step 1) violates data hiding, which leads to tight coupling between the code and the tests.  Over the years, however, I’ve realized that there’s a much deeper issue with the steps above - you can probably guess what it is from the title of this post. J  Here’s my opinion:

 

The  xUnit tools often foster a testing methodology which violates a fundamental tenet of XP/Agile programming - Once and Only Once. 

 

This is because xUnit encourages developers to put validation code in the test (step 3), i.e. outside the method being tested.  This is turn results in either duplication of the validation code in multiple tests, or architectural complexity in the test component to ensure that the same validation code is called from multiple tests.  Obviously, I think the solution to this dilemma lies in the introduction of contract checks, but that will have to wait until Part II....

 

 

You might also like...

c138_2_cropped
3 Min read
3D ACIS
We often focus the success of new partners, showcasing how Spatial helped with bringing a new product to market. But...
Large Tolerant  Vertex
3 Min read
3D Software Development Kits
boolean operation Boolean operations on individual bodies are common functions in 3D modeling. While simple in concept,...
3 Min read
3D Software Development Kits
In much the same way as physical design has moved from paper 2D drawings to 3D models in software, so has analysis....
4 Min read
3D InterOp
Part and parcel with model-based engineering is model translation. Because the model is now the specification, accurate...
4 Min read
3D ACIS
We are moving things around in the office here at Spatial to accommodate some new people. As a result, our marketing...
2 Min read
3D ACIS
This article shares a simple architecture which can be used to capture meta-data about the use of ACIS APIs in your...
1 Min read
3D ACIS
How To Create an Ellipsoid using 3D ACIS The 3D analytics supported directly in 3D ACIS include: sphere, block,...
2 Min read
3D ACIS
Basically, there are two priorities when using a software component, particularly a 3D modeling kernel: Does it do what...
1 Min read
3D ACIS
A geometry kernel is a big thing. It’s a huge thing. Maybe even big enough to see from space. By most accounts, even...
1 Min read
3D ACIS
My comrades and I did a performance analysis of Intel’s Hyper Threading Technology (HTT), using thread-safe ACIS and...
3 Min read
3D ACIS
In earlier posts I’ve written a lot about the various approaches to multiprocessing and the potential benefits. What I...
2 Min read
3D ACIS
The challenges of a major software release are not unique to Spatial. And like other organizations, the launch process...
5 Min read
3D ACIS
We’ve known for a long time that the integrity of B-rep data plays a major role in the success of downstream modeling...
3 Min read
3D ACIS
Answer: when it’s a 'HappyPathPoint'.
1 Min read
3D ACIS
To finish up this series of posts; what Gregg's post described happened a few years ago. Since that first team room,...
4 Min read
3D ACIS
This post will discuss two aspects of my favorite programming language, C++:
2 Min read
3D ACIS
Way back in the Dark Ages of the mid-90s, I used to read a newsgroup called comp.lang.c++. You can tell this was the...
7 Min read
3D ACIS
Here’s a subject to which everyone can relate in one way or another: growable arrays. An array is a contiguous memory...