Go 单元测试

Submitted by Lizhe on Fri, 10/26/2018 - 13:57

 

 

package lizhe

 

import (

    "errors"

)

 

func Division(a, b float64) (float64, error) {

    if b == 0 {

        return 0, errors.New("除数不能为0")

    }

 

    return a / b, nil

}

 

 

package lizhe

 

import (

    "testing"

)

 

func Test_Division_1(t *testing.T) {

    if i, e := Division(6, 2); i != 3 || e != nil {

        t.Error("除法函数测试没通过")

    } else {

        t.Log("第一个测试通过了")

    }

}

 

func Test_Division_2(t *testing.T) {

    t.Error("就是不通过")

}

 

 

20181026020005

 

20181026020013