Java Reference
In-Depth Information
code coverage of the Calculator class, indicating that developers need to create
more tests.
Depending on how you compose your application, it might not be possible to reach
all code in the test environment. You may consider refactoring your code to allow for
better coverage in combination with the use of mock objects or stubs. 1 Whether you
choose this approach to reach 100 percent code coverage is a policy decision your team
can review through the development cycle.
5.1.4
Combining black box and white box testing
If we can achieve higher test coverage with white box unit tests, and we can generate
reports to prove it, do we need to bother with black box tests?
If you think about the differences between figure 5.1 and figure 5.2, there's more
going on than how many methods the tests execute. The black box tests in figure 5.1
are verifying interactions between objects. The white box unit tests in figure 5.2, by
definition, don't test object interactions. If a white box test does interact with another
object, that object is usually a stub or a mock object designed to produce specific test
behavior (see chapters 6 and 7).
Figure 5.4
Class code coverage with Cobertura
1
You'll learn about stubs in the next chapter and about mocks in chapter 7.
 
 
 
 
 
 
 
Search WWH ::




Custom Search