自动化测试仪器

Instrumentation for Automated Testing

写一个java程序获取JUnit测试用例的语句覆盖率?

例如:

public Integer addIfXGreaterThanY(int x, int y){
   Integer z = null;

   if (x > y) {
       z  = x + y;
   }
   else {
      z = x - y;
   }

   return z;
}

输出:

Test case 1 inputs:  10, 15
output(line numbers covered):  1, 2, 5, 6
and another call will produce:
Test Case 2 inputs: 15, 10
output(line numbers covered): 1, 2, 3, 6

我想你想要的是 code coverage. Emma is one popular tool for JUnit code coverage. The answers at this question 还有其他一些选择。

听起来您正在寻找代码覆盖率报告工具。这些库提供了测试用例(通常包括 junit)覆盖和遗漏的代码行和分支。 Jacoco 和 cobertura 等工具通常会通过测试提供方法中涵盖的行和分支。 java code coverage tools 的更多示例可用。就个人而言,我以前使用过 jacoco 和 junit。

也许您想要 comparison 一些现有的代码覆盖工具?