9 | Unit Testing with A8AP Unit
example, if you find that a given module is difficult to test, there is likely some-
thing wrong with it.
Finally, unit tests should inspire you with the confidence to take "risks" in your
development. For instance, in Chapter 5, Inheritance, we discussed the concept
of refactoring to improve the design of some existing code. Without unit testing,
you might be hesitant to perform certain refactorings for fear of breaking some
unforeseen dependent code. Similarly, you might also be cautious about imple-
menting enhancements for the same reasons. However, with unit tests, you can
apply the changes and know immediately whether or not you broke something in
the system without having to conduct a full-scale regression test.
9.7 UML Tutorial: Use Case Diagrams
Even if you haven't spent much time working with the UML before, it is likely
thatyou may have heard the term use case used in various contexts at one time or
another. Use cases are an important part of the UML standard, although ironi-
cally, the UML specification has very little to say about how to actually define
one. Instead, it focuses on the use case diagram, which only tells a very small part
of the story.
In his book Writing Effective Use Cases (Addison-Wesley, 2001), Alistair Cockburn
defines a use case as something that "... captures a contract between the stake-
holders of a system about its behavior." In other words, you can think of a use
case as a method for capturing the functional requirements of
a
system or mod-
ule. A use case is fairly succinct, describing a single interaction scenario between
a requesting user or system (referred to as an actor) and the system under discus-
sion. Each use case defines a main success scenario that defines how an actor can
achieve its goal. At each step within the main success scenario, it is highly possi-
ble that something might occur to cause the flow of the use case to deviate. These
deviation scenarios are referred to as extensions. Separating these extension sce-
narios from the main success scenario makes the use case much easier to read.
Use case development is a collaborative process that requires a lot of communica-
tion within a project team. Most of the time, this process is driven heavily by
business analysts that may not be familiar with the UML. Therefore, use case sce-
narios are often best represented in text form. You will see an example of this
form in Section 9.7.2, An Example Use Case.
248