Reputation: 141
I've only just begun learning about Test Driven Development and Unit Testing, but it seems that both concepts rely quite heavily upon the use of Interface constructs. Given that an Interface is an abstract construct, without implementation, it seems to me that the data exposed by an Interface must be re-validated by anything consuming the Interface. So I'm wondering... Do testable designs actually require continuous validation, or am I missing something?
Upvotes: 2
Views: 60
Reputation: 37960
An interface is often considered to be a contract which (through its documentation) specifies rules for how its implementors are supposed to behave. Even though the compiler cannot see or verify that the implementors follow those rules, the program just assumes that all implementors follow the rules. For instance, given
public interface IPersonInfo {
// Returns a valid social security number.
String getSocialSecurityNumber();
}
the consumers of the interface will normally assume that the implementor will only return valid social security numbers, so that the consumer does not need to revalidate it. This, of course, assumes that you trust the implementing code; if this is e.g. an interface for an external web service or a third-party plugin, you might want to validate the return values. However, the general approach is to say that within a single program, it is assumed that the informal rules will be followed by implementors (and the unit tests typically test the "canonical" implementation) and accept that the program will misbehave if someone starts using a nonconforming implementation.
Upvotes: 1