Juit的使用

今天学习了JUNIT的知识跟大家分享一下。
首先是JUNIT的配置过程。
1.首先要下载eclipse,junit和junit_src网上都能找到对应的软件。
2.安装
第一步:打开Eclipse->Window->preferences.
第二步:Java->Build Path->Class Variable,新建两个变量JUNIT和JUNIT_SRC,将junit和junit_src的路径指定到这两个变量中。如下图所示:
[img]C:\Users\Administrator\Desktop\a.png[/img]
第三步:创建工程,右击工程属性->java bulid path->libraries->add variable
将新创建的变量JUNIT加载进去。
第四步:JUNIT->Sourse attachment,将创建的变量JUNIT_SRC加载进去。
3.测试
被测代码:
public class Hello {

public int number(){
return 4;
}
public boolean yesOrNo(){
return true;
}
}
测试代码:
package com.mini;

import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class HelloTest extends TestCase{


int _expectedNumber;

boolean yesorno;
Hello _hello;

@Before
public void setUp() throws Exception {//测试前要调用的方法
_expectedNumber = 5;
yesorno = false;
_hello = new Hello();
}

@After
public void tearDown() throws Exception {//测试后要调用的方法
}

@Test
public void testMain() {//测试执行的方法

assertEquals(_expectedNumber, _hello.number());
//assertEquals(yesorno,_hello.yesOrNo());

}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值