关于DJUnit问题。

xiaobei0623 2011-08-08 03:54:41
public class test1 {


public test1()
{

}

public int testaa()
{
return 1;
}

}

--------------------------
public static void main(String[] args) {

test1 test=new test1();

int i=test.testaa();

if(i==1)
{
System.out.println("11111");
}
else
{
System.out.println("22222222");
}
}

-------------------------------------
public void testMain001() throws Exception {

addReturnValue(test1.class, "testaa",2);

String[] args = {""};
Main.main(args);
}
--------------------------------------------
我已经指定testaa的返回值为2了,为何在跑测试的时候打印出来的还是11111呢?
...全文
439 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouweixin2017 2011-12-12
  • 打赏
  • 举报
回复
你的int i=test.testaa(); 返回值就是1, if语句泡不到else。要想测试 else 就重新写测试用列。让int i=test.testaa()的返回值是2
xiaobei0623 2011-08-09
  • 打赏
  • 举报
回复
mock这东西没人能帮解决了?
cchlovewq 2011-08-09
  • 打赏
  • 举报
回复
也想学习学习,帮顶一下。
xiaobei0623 2011-08-09
  • 打赏
  • 举报
回复
请哪位高手指点一下,如何测试能走到ELSE里面去。
xiaobei0623 2011-08-08
  • 打赏
  • 举报
回复
哪位高手指点一下,如何用DJUnit
xiaobei0623 2011-08-08
  • 打赏
  • 举报
回复
import jp.co.dgic.testing.framework.DJUnitTestCase;

public class MainTest extends DJUnitTestCase {

public MainTest(){
super(null);
}

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

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

public void testMain001() throws Exception {

我知道main()方法是程序入口,我用的是DJUnit,只是想写测试方法,让它走到ELSE里面去。
哪位高手指点一下。主要是想测试一下如何mock方法。
zl3450341 2011-08-08
  • 打赏
  • 举报
回复
public void testMain001() throws Exception {

addReturnValue(test1.class, "testaa",2);

String[] args = {""};
Main.main(args);
}

1。addReturnValue这是一个什么东西?

2。你在类里面定义了main()方法,main方法是一个程序的入口,这点难道你不知道么?
test1 test=new test1();

int i=test.testaa();

if(i==1)
{
System.out.println("11111");
}

明显就会打印1111


你这个题跟Junit一点关系都没有。。

在网上找找资料,看下Junit怎么用的

你运行你的类,他就跑到main()方法里面去了。
xiaobei0623 2011-08-08
  • 打赏
  • 举报
回复
addReturnValue(test1.class, "testaa",2);

我已经把它mock为2了。
可能是我写的不正确,有哪位高手指点一下。
softroad 2011-08-08
  • 打赏
  • 举报
回复

public int testaa()
{
return 1;
}

好好看看你代码,命名返回1,愣是说返回2
大灰兔 2011-08-08
  • 打赏
  • 举报
回复
楼主addReturnValue方法是怎样的?

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧