您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源單元測(cè)試工具 > junit
JUnit4單元測(cè)試簡(jiǎn)單入門
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2016/7/14 11:48:30 ] 推薦標(biāo)簽:單元測(cè)試 軟件測(cè)試工具

  在類名上面點(diǎn)擊右鍵生成test測(cè)試類


  測(cè)試類生成截圖


測(cè)試類名,勾選測(cè)試方法

  會(huì)在測(cè)試類的包中自動(dòng)生成測(cè)試類
package com.example.news;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by 小新 on 2016/7/1.
*/
public class CalculatorTest {
@Before
public void setUp() throws Exception {
}
@Test
public void testSum() throws Exception {
}
@Test
public void testSubstract() throws Exception {
}
@Test
public void testDivide() throws Exception {
}
@Test
public void testMultiply() throws Exception {
}
@Test
public void testAddMore() throws Exception {
}
}
  然后進(jìn)行測(cè)試
package com.example.news;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by 小新 on 2016/7/1.
*/
public class CalculatorTest1 {
private Calculator calculator;
@Before
public void setUp() throws Exception {
calculator = new Calculator();
}
@Test
public void testSum() throws Exception {
//測(cè)試sum函數(shù),因?yàn)閟um函數(shù)返回的是兩個(gè)數(shù)的合為3
//這里期望返回的值是9
//所以會(huì)報(bào)錯(cuò)
assertEquals(9d,calculator.sum(1d,2d),0);
}
@Test
public void testSubstract() throws Exception {
}
@Test
public void testDivide() throws Exception {
}
@Test
public void testMultiply() throws Exception {
}
@Test
public void testAddMore() throws Exception {
}
}
  運(yùn)行這個(gè)類,結(jié)果為報(bào)錯(cuò),這個(gè)時(shí)候我們需要修改函數(shù)了
  到這里我們JUnix的簡(jiǎn)單測(cè)試結(jié)束了

上一頁(yè)12下一頁(yè)
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd