这种方法有什么好的测试用例?

时间:2016-01-12 17:08:22

标签: java unit-testing

本学期我参加了软件测试课程,并开始学习第一章。我对这种方法很困惑,为什么它被认为是有缺陷的。 在执行该软件的计算机上使用16位实现整数,最低输入值为-32768,最高值为32767.

/**
 * 
 * This is a example program in the book for software testing called
 * A practitioner's Guide to Software Test Design
 * I don't understand why the book says that the weakness of this program
 * is that the method will need to create a new memory slot for a larger
 * integer.  Why is that a problem?  The program doesn't crash.
 */
public class TestCase {

  //The book test these values and states that these are not successful test
  //cases.  Why is that?  
  public static void main(String[] args) {
    System.out.println(testCase(bla(1),0));
    System.out.println(testCase(bla(42),0));
    System.out.println(testCase(bla(40000),1));
    System.out.println(testCase(bla(-64000),-2));
  }

  public static int bla(int arg){
    arg = arg - 1; // should be arg = arg + 1
    arg = arg/30000;
    return arg;
  }

  public static boolean testCase(int i, int test){
    return (i == test) ? true : false;      
  }

}

我已经向老师询问了这个问题,但我不认为她确切知道这是错误的原因。

那么这个问题的正确测试案例是什么?更多,所以我不明白,如果问题是需要为16位系统中的另一个int分配新的内存槽,为什么这是一个问题。有人可以详细说明吗?

0 个答案:

没有答案