Dong.Ge

左手代码 右手江湖

golang goconvery

东哥's Avatar 2019-05-10

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package wcd

import "errors"

func Wcd() string {
return "ok"
}

func Division(a, b int) (int, error) {
if b == 0 {
return 0, errors.New("被除数不能为 0")
}
return a / b, nil
}

func Con() string {
return "wcd"
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package wcd

import (
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func TestWcd(t *testing.T) {
Convey("wcd测试", t, func() {
So(Wcd(), ShouldEqual, "ok")
})
}

func TestDivision(t *testing.T) {
Convey("将两数相除", t, func() {

Convey("除以非 0 数", func() {
num, err := Division(10, 2)
So(err, ShouldBeNil)
So(num, ShouldEqual, 5)
})

Convey("除以 0", func() {
_, err := Division(10, 0)
So(err, ShouldNotBeNil)
})
})
}

func TestContains(t *testing.T) {
Convey("包含", t, func() {
So(Con(), ShouldContainSubstring, "wcd")
})
}


本文最后更新于 天前,文中所描述的信息可能已发生改变