go test

Jmnote (토론 | 기여)님의 2023년 5월 27일 (토) 11:49 판 (→‎개요)

1 개요

go test
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

2 같이 보기

3 참고

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