go test

Jmnote (토론 | 기여)님의 2024년 5월 8일 (수) 13:02 판 (→‎같이 보기)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

go test
$ go test
PASS
ok      example.com/greetings   0.364s
$ go test -v
=== RUN   TestHelloName
--- PASS: TestHelloName (0.00s)
=== RUN   TestHelloEmpty
--- PASS: TestHelloEmpty (0.00s)
PASS
ok      example.com/greetings   0.372s

2 실습[ | ]

root@localhost:~/go/src/pkg1# ll
total 16
drwxr-xr-x   2 root root   41 Apr  9 18:33 ./
dr-xr-x---. 50 root root 4096 Apr  9 17:55 ../
-rw-r--r--   1 root root  126 Apr  9 18:33 pkg1.go
-rw-r--r--   1 root root  303 Apr  9 18:33 pkg1_test.go
pkg1.go
package pkg1

func Abs(x int) int {
        if( x < 0 ) {
                x = x * -1
        }
        return x
}

func Multiply(x, y int) int {
        return x * y
}
pkg1_test.go
package pkg1

import "testing"

func TestAbs(t *testing.T) {
        got := Abs(-1)
        want := 1
        if got != want {
                t.Errorf("Abs(-1) = %d; want %d", got, want)
        }
}

func TestMultiply(t *testing.T) {
        got := Multiply(3,5)
        want := 15
        if got != want {
                t.Errorf("Multiply(3,5) = %d; want %d", got, want)
        }
}
root@localhost:~/go/src/pkg1# go test
PASS
ok      _/root/lets_go_test     0.002s
root@localhost:~/go/src/pkg1# go test -v
=== RUN   TestAbs
--- PASS: TestAbs (0.00s)
=== RUN   TestMultiply
--- PASS: TestMultiply (0.00s)
PASS
ok      _/go/src/pkg1/pkg1_test     0.002s

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}