測(cè)試類(lèi)生成截圖
測(cè)試類(lèi)名,勾選測(cè)試方法
會(huì)在測(cè)試類(lèi)的包中自動(dòng)生成測(cè)試類(lèi)
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è)類(lèi),結(jié)果為報(bào)錯(cuò),這個(gè)時(shí)候我們需要修改函數(shù)了
到這里我們JUnix的簡(jiǎn)單測(cè)試結(jié)束了