📄 lib0119.html
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Testing Coverage</title>
<link rel="STYLESHEET" type="text/css" href="images/xpolecat.css">
<link rel="STYLESHEET" type="text/css" href="images/ie.content.css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle" alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0118.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0120.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
<br>
<div class="chapter">
<a name="ch18"></a>
<div class="section">
<h2 class="first-section-title"><a name="585"></a><a name="ch18lev1sec2"></a>Testing Coverage</h2><p class="first-para">Most developers already code test cases for classes they write to allow for unit testing and debugging. Given this, writing formal test cases that can later be executed in a test suite usually doesn't take much additional work. This section shows you how to write test cases within the JUnit framework.</p>
<p class="para">
<b class="bold">Selectively choose test case coverage.</b> Ideally, you should code test cases for all public methods in all classes. Realistically, however, most projects achieve something less than the ideal, at least in the beginning. Again, I initially apply the 80/20 rule. It's more important to have basic test cases for the most complex places in the application because these places have a greater chance of containing bugs. It's most convenient to create test cases as you write the code. I typically ask developers for one test case per public method for every data access object and business object in the application.</p>
<p class="para">Asking for one test case per method or service call is by no means comprehensive, but it's a sensible start. Over time, this test case library can be enhanced and will provide good automatic regression testing capabilities. If developers use a testing framework such as JUnit, the test cases should be combinable into test suites.</p>
<p class="last-para">When investigating a bug report, most developers will try to replicate the bug. At some point in the investigation, the developer will find out which classes contain the bug. For most bugs, it's not too much additional work to create a test case (or modify an existing one) to replicate the bug and include it in the test suite. This gives the developer a smaller section of code to debug. It also contributes to a more robust regression test. The regression test should be executed on a periodic basis (even on a scheduled basis, with errors mailed to the development team).</p>
</div>
</div><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle" alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0118.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0120.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -