Skip to content

Commit 57c12da

Browse files
authored
Merge pull request #540 from devlights/add-go-test-example
2 parents f9141f2 + 9e8f3f4 commit 57c12da

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
run:
2+
go test -v .
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 概要
2+
3+
Go では、テストを作成する際にパッケージを
4+
5+
- 対象パッケージ
6+
- 対象パッケージ_test
7+
8+
の2つを使うことが出来ます。
9+
10+
そして、この2つは例外として共存出来ます。
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package testpkgcoexist
2+
3+
import "testing"
4+
5+
func TestA(t *testing.T) {
6+
var (
7+
a, b = 1, 10
8+
)
9+
10+
c := a * 10
11+
if c != b {
12+
t.Errorf("[want] %v\t[got] %v", b, c)
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package testpkgcoexist_test
2+
3+
import "testing"
4+
5+
func TestB(t *testing.T) {
6+
var (
7+
a, b = 1, 10
8+
)
9+
10+
c := a * 10
11+
if c != b {
12+
t.Errorf("[want] %v\t[got] %v", b, c)
13+
}
14+
}

0 commit comments

Comments
 (0)