清單 9. 使用 JUnit 規避風險
package test.com.vanward.coverage.example02;
import junit.framework.TestCase;
import com.vanward.coverage.example02.AnotherBranchCoverage;
public class AnotherBranchCoverageTest extends TestCase {
public final void testBranchIt() {
AnotherBranchCoverage clzzUnderTst = new AnotherBranchCoverage();
clzzUnderTst.branchIt(101);
}
}
您對這個測試案例有什么想法?您也許會寫出更多的測試案例,但是請設想一下清單 7 中不確定的條件有不止一個的縮短操作會如何。設想如果前半部分中的邏輯比簡單的 int 比較更復雜,那么您 需要寫多少測試案例才能滿意?
僅僅給我數字
現在,對清單 7、8、9 的測試覆蓋率的分析結果不再會使您感到驚訝。在圖 4 的報告中顯示我達到了 75% 的行覆蓋率和 100% 的分支覆蓋率。最重要的是,我執行了第 10 行!
圖 4.愚弄的報酬
文章來源于領測軟件測試網 http://www.kjueaiud.com/