复利计算4.0-单元测试

对我们和复利计算程序,写单元测试。 

   有哪些场景?

   期待的返回值

   写测试程序。

   运行测试。

完成了客户要求的复利计算程序,但为了完善程序,所以进行了单元测试

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 }

原文地址:https://www.cnblogs.com/chenkaiqi/p/5338573.html