對我們和複利計算程式,寫單元測試。
有哪些場景?
期待的傳回值
寫測試程式。
運作測試。
完成了客戶要求的複利計算程式,但為了完善程式,是以進行了單元測試
1 package tests;
2
3 import com.exxample.junit.Fuli;
4 import junit.framework.Assert;
5 import org.junit.Before;
6 import org.junit.Test;
7
8 /**
9 * Created by lenovo on 2016/3/28.
10 */
11 public class FuliTest {
12 private Fuli fulitext;
13
14 @Before
15 public void setUp() throws Exception {
16 fulitext =new Fuli();
17
18 }
19
20 @Test //測試數值期望值相等
21 public void testCaMoney() throws Exception {
22 double result=fulitext .CaMoney(100,0.02,5);
23 Assert.assertEquals(110.40808032,result);
24
25 }
26
27 @Test
28 public void testCaBMoney() throws Exception {
29 double result=fulitext .CaAMoney(100,0.02,10) ;
30 Assert.assertEquals(1116.8715419732623,result);
31 }
32
33 @Test //測試極限的大小
34 public void testCaValue() throws Exception {
35 double result=fulitext .CaValue(10000000,0.02,100000);
36 Assert.assertTrue(result==0 );
37 }
38
39
40
41
42 }
