Design tests

From DesignWizardWiki

Jump to: navigation, search

We introduce a new kind of test named Design Test. The goal of Design Tests is to specify the desired design by writing tests that make assertions about the structure of the code been developed.

The code bellow shows an example of Design Test. It specifies the desired behavior for communication between classes from a project. First of all, let A and B be classes from a given project. Now, let us assume that the designer from the project does not want to allow that class A uses class B, that is, there must not be any call of method or access to any attribute from class B in class A. An algorithm that describes this behavior is presented bellow:

for method in class A {
  set = method.getClassesUsedBy();
  assert !set.contains(class B);
}

As we can see on the code above, a Design Test needs structural information about relationships of the entities from the code to be tested to describe the expected structure of the design.

The usage of design tests continuously on the development process brings a several number of benefits, like the increase of confidence in the quality of the code's design. Furthermore, programmers have the exactly idea whether the code developed is in conformance with the specified design. Besides that, it increases the reliability on the refactoring process, once design tests will verify whether the refactoring does not break the rules specified previously.

Personal tools