Java Reference
In-Depth Information
As you can see, we can analyze a use case and identify the methods that are
called by the domain model's client. We can use this process to analyze the other
steps of the Place Order use case and identify additional methods. Once you have
identified these methods, the next step is to implement them.
Implementing methods using test-driven development
At this point in the development process, we have identified methods specified by
the PlaceOrderService and RestaurantRepository interfaces and some simple
getters defined by the Restaurant class. We now need to implement these meth-
ods. There are several ways to go about this. My favorite approach is to use test-
driven development [Beck 2002], which is an informal, code-centric, and incre-
mental development technique. When using test-driven development, you first
write automated unit test cases for the new functionality. You then write the code
that implements the functionality and makes the tests pass.
For example, when using test-driven development to implement a service
method such as PlaceOrderService.updateDeliveryInfo() , you begin by writing
one or more test cases. Each test calls the method with a particular combination
of arguments and verifies that it correctly updates PendingOrder and returns the
expected result. After writing the tests, you then implement the service method
and make them pass. The output of test-driven development is working and tested
code and automated test cases. In addition to ensuring that the code works, the
tests document the expected behavior of the application.
In order to successfully use test-driven development, you need a development
environment that provides immediate feedback to small changes. The process of
writing a test and making it pass happens many times a day. Refactoring , a process
that improves the design and that we describe in a moment, also consists of mak-
ing small changes and testing them. As a result, it is common to go through the
edit-compile-debug cycle every couple of minutes or even less. You can't wait for
EJB s to deploy or for the database to be rebuilt if you want to be productive. As you
can see, test-driven development and lightweight technologies work well together.
The importance of refactoring your code
Test-driven development is very different from development techniques that
involve a lot of up-front design because the design incrementally evolves as more
tests are written. But one risk of evolving a design is that you could end up with an
unstructured mess. To prevent this from happening, it's important to periodically
refactor the code.
 
 
 
Search WWH ::




Custom Search