复利计算器单元测试测试报告

初次尝试进行单元测试,要怎么开始单元测试也是无从下手,后来通过Grey老师关于单元测试的博客中学习http://www.cnblogs.com/greyzeng/p/4439080.html

终于利用Junit进行了部分单元测试。

但是还是不能好好实现要测试的代码,不知道如何判断年限和利润等的合法输入,返回true和false值。

public void testInputYear(){
        boolean result=true;
        int year=Compounding.InputYear(-1);
        if(year<0||year>100)
        result= false;
        else 
        result=true;
        assertEquals(false, true);
    }

可能是没搞懂应该怎么编写代码,导致代码的错误,每次的测试都是红色条条。

所以只测试了部分计算过程的结果是否正确。

@Test
    public void testCompoundYear() {
        int compoundYear = Compounding.compoundYear(1000000, 0.1, 2000000);
        assertEquals(7, compoundYear);
    }

测试模块

测试输入

预期结果

运行结果

bug跟踪

计算终值

(本金,年限,利率)

终值

   

1

(1000000, 30, 0.03)

2427262.471189663

 

2

(-1000000, 30, 0.03)

弹出提示:请输入>0的本金

3

(1000000, -30, 0.03)

弹出提示:请输入>0的存钱年数

4

(1000000, 30, -0.03)  弹出提示:请输入>0的利率  √  
5  (1000000, 30, 3)  弹出提示:请输入<1的利率  √  

计算本金

(年限,利率,终值)

         本金

   

1

(30, 0.03,3000000)

1235960.278547719

 
原文地址:https://www.cnblogs.com/zou779596337/p/5334336.html