-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_test.go
68 lines (58 loc) · 1.42 KB
/
hello_test.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import "testing"
// test function names begin with uppercase Test
func TestMessage(t *testing.T) {
project := new(Project)
project.PushedAt = "now"
project.Name = "TestProject"
msg := Message(project)
if msg != "<p>TestProject: Latest commit: now</p>" {
t.Errorf("Incorrect message: %s", msg)
}
}
func TestMessageLackOfPushAt(t *testing.T) {
project := new(Project)
project.Name = "TestProject"
msg := Message(project)
if msg != "<p>TestProject: Latest commit: </p>" {
t.Errorf("Incorrect message: %s", msg)
}
}
func TestMessageLackOfName(t *testing.T) {
project := new(Project)
project.PushedAt = "now"
msg := Message(project)
if msg != "<p>: Latest commit: now</p>" {
t.Errorf("Incorrect message: %s", msg)
}
}
func TestFailCase(t *testing.T) {
project := new(Project)
project.PushedAt = "sssss"
msg := Message(project)
if msg != "<p>: Latest commit: now</p>" {
t.Errorf("Incorrect message: %s", msg)
t.Fail() // Bắt lỗi ở đây
}
}
func TestFailCaseSystemError(t *testing.T) {
// Arrange
project := new(Project)
project.PushedAt = "sssss"
panic(1)
// Act
func() {
defer func() {
if r := recover(); r != nil {
// Assert
t.Logf("Expected system error: %v", r)
return
}
}()
// This will cause a panic and a system error
msg := Message(project)
_ = msg // To avoid "unused variable" warning
}()
// If the code reaches here, the test should fail
t.Fail()
}