Behavior-driven development: Difference between revisions

Content deleted Content added
Line 64:
When writing behavioral tests there are number of practical rules to keep in mind that will help developers to stay on track with the goals of testing behavior instead of implementation. These numbers aim to make both tests and application code and design as flexible and robust as possible.
 
* '''Test size''': each test (that is each test method) should not be longer than 15 lines of code (not counting empty lines). Test methods that are longer are either too complex (or the implementation is inefficient) or test too much behavior. Small tests are more expressive - it's easier to understand the behavior that is tested - and are easier to maintain and [[refactor]].
* '''Mock objects''': the usage of mock objects is encouraged (e.g. by using the [[EasyMock]] framework for Java) to achieve the previous goal. Mock framework create easy to use - and verify - objects that make tests more accurate, shorter and easier to maintain since the framework creates the implementation of the objects, not the developers that write the behavioral tests.
* '''Helper methods''': some behavior is best implemented in a helper method (e.g. load this or that from the database) that can be easily tested and called from elsewhere in the application. These methods help to make the code more expressive (through expressive method and argument names) and easier to test.
* '''No dependencies''': behavioral tests should not depend on other test cases, the execution order of tests or test cases or the presences of any configured system. This assures that only a limited, well-defined behavior in tested in a fine-grained manner. The opposite is to test fully configured application (components) in a coarse-grained matter. This aspect of these an application is important yet it is the ___domain of [[Integration tests]].
* '''Isolated''': behavioral tests should work in full isolation to ensure only a very limited part of the entire behavior of an application is tested. The more fine-grained behavioral tests are the better the behavior is tested.
 
Specifically for Java there are two more rules: