"Go test"의 두 판 사이의 차이

(새 문서: ==개요== <syntaxhighlight lang='console'> root@localhost:~/lets_go_test# 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 ../ -r...)
 
67번째 줄: 67번째 줄:
==참고==
==참고==
* https://golang.org/pkg/cmd/go/internal/test/
* https://golang.org/pkg/cmd/go/internal/test/
* https://www.digitalocean.com/community/tutorials/how-to-write-unit-tests-in-go-using-go-test-and-the-testing-package


[[분류: Go CLI]]
[[분류: Go CLI]]
[[분류: Go 테스트]]
[[분류: Go 테스트]]

2021년 4월 9일 (금) 18:38 판

1 개요

root@localhost:~/lets_go_test# 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
root@localhost:~/lets_go_test# cat 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
}
root@localhost:~/lets_go_test# cat 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:~/lets_go_test# go test
PASS
ok      _/root/lets_go_test     0.002s
root@localhost:~/lets_go_test# go test -v
=== RUN   TestAbs
--- PASS: TestAbs (0.00s)
=== RUN   TestMultiply
--- PASS: TestMultiply (0.00s)
PASS
ok      _/root/lets_go_test     0.002s

2 같이 보기

3 참고

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