|
Leverage the use of dependency frameworks
If the architecture permits the use of frameworks, consider using a dependency injection framework like Spring. Spring framework allows externalizing the dependencies by moving them to a configuration file (xml file). The advantages are:
* A nice clean way of managing dependencies
* Sparse use of singletons
* Easy to plug in and out different implementations of the dependencies
* In built support for unit testing
Define and document the method functionality
The method documentation should clearly state what the method is expected to do. If there are branches within the method, the documentation should explain the conditional logic. Consider giving as much documentation as possible to help the unit test developer to understand the method’s purpose.
Define and document the method contract
Design by contract (DBC) is a way of writing the method documentation so that it clearly defines what the code will do. It should clearly capture the preconditions, post conditions and any invariants should be clearly documented.
The following tags can be used for method documents:
@pre – Conditions that have to be true before method can be called
@post – Conditions that should be true after the method gets executed
@invariant – This is a constraint on the object state that is guaranteed to be true at all times, such as Collection.size() == Collection.toArray().length().
In the detailed design phase when identifying methods and behavior of classes, also identify the contract of the method. This contract specifies terms under which the code will be executed. The contract defines the following and this has to be documented in the method specification.
* Input – Range of expected values for the input(s) of the method
* Output - Range of expected values for output(s) of the method
* Boundary - Clearly state the boundary conditions for the method. The conditions in which the method would fail (negative flows)
* Exception – The cases when the method would fail by an exception. Document the input values that could cause this. Document the expected behavior of the system when the method fails through an exception.
* Assumptions – Document the assumptions (if any) on how the method will behave. For example methods that deal with data in some formats should document the format. The assumption is that the data format would not change. |
|