lilioooo 2009-09-21 18:49
浏览 220
已采纳

junit怎么用?

写了个很简单的测试用例,可是老是显示测试失败。netbean6.7.1
被测试类:
package javaapplication4;
public class NewClass {
public int add(int a,int b){
return a+b;
}
}

测试类
/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor. */

package javaapplication4;
import junit.framework.TestCase;
public class NewClassTest extends TestCase {
public NewClassTest(String testName) {
super(testName);
}

@Override
protected void setUp() throws Exception {
    super.setUp();
}

@Override
protected void tearDown() throws Exception {
    super.tearDown();
}
/**
 * Test of add method, of class NewClass.
 */
public void testAdd() {
    System.out.println("add");
    int a = 3;
    int b = 4;
    NewClass instance = new NewClass();
    int expResult = 7;
    int result = instance.add(a, b);
    assertEquals(expResult, result);
    // TODO review the generated test code and remove the default call to fail.
    fail("The test case is a prototype.");
}

}

测试类基本都是netbean自己写的,现在测试老是显示失败
Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.016 sec
------------- Standard Output ---------------
add


Testcase: testAdd(javaapplication4.NewClassTest): FAILED
The test case is a prototype.
junit.framework.AssertionFailedError: The test case is a prototype.
at javaapplication4.NewClassTest.testAdd(NewClassTest.java:42)
Test javaapplication4.NewClassTest FAILED

  • 写回答

1条回答 默认 最新

  • iteye_19077 2009-09-21 19:14
    关注

    // TODO review the generated test code and remove the default call to fail.
    应该和这句注释有关,这句话的意思: 检查产生的测试代码并且删除默认的fail 方法的调用,
    所以你应该把 这句注释和fail方法的调用的这两行删掉。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体