Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fa96f34

Browse files
20220422
1 parent 7c71074 commit fa96f34

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ps:白天上班,晚上更新,尽量日更,比心
7171

7272
[第31章 sync.pool对象缓存](https://github.com/java-aodeng/golang-examples/blob/master/go-31/sync_pool_test.go)
7373

74-
第32章 单元测试
74+
[第32章 单元测试](https://github.com/java-aodeng/golang-examples/blob/master/go-32/function_test.go)
7575

7676
第33章 Benchmark
7777

‎go-32/function_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package go_32
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
/*
9+
内置单元测试框架
10+
- Fail,Error:该测试失败,该测试继续,其他测试继续执行
11+
- FailNow,Fatal:该测试失败,该测试中止,其他测试继续执行
12+
13+
*/
14+
15+
func TestErrorInCode(t *testing.T) {
16+
fmt.Println("Start")
17+
t.Error("Error")
18+
fmt.Println("End")
19+
}
20+
21+
func TestFailInCode(t *testing.T) {
22+
fmt.Println("Start")
23+
t.Fatal("Error")
24+
fmt.Println("End")
25+
}
26+
27+
/*
28+
运行结果:
29+
=== RUN TestErrorInCode
30+
Start
31+
End
32+
--- FAIL: TestErrorInCode (0.00s)
33+
function_test.go:17: Error
34+
=== RUN TestFailInCode
35+
Start
36+
--- FAIL: TestFailInCode (0.00s)
37+
function_test.go:23: Error
38+
FAIL
39+
40+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /