Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Go言語のテスト

More than 1 year has passed since last update.

ディレクトリ構成
cal/calc.go
cal/calc_test.go

calc.go
package calc

func sum(a, b int) int {
    return a + b
}

func minus(a, b int) int {
    return a - b
}
calc_test.go
package calc

import "testing"

func TestSum(t *testing.T) {
    if sum(1, 2) != 3 {
        t.Fatal("sum(1,2) should be 3, but doesn't match")
    }

    if sum(4, 9) != 12 {
        t.Fatal("sum(4,9) should be 13, but doesn't match")
    }
}

func TestMinus(t *testing.T) {
}

テストの実行

go test -v ./calc
=== RUN   TestSum
--- FAIL: TestSum (0.00s)
    calc_test.go:11: sum(4,9) should be 13, but doesn't match
=== RUN   TestMinus
--- PASS: TestMinus (0.00s)
FAIL
FAIL    _/Users/bob/calc    0.010s

テストのカバレッジを確認

go test -cover ./calc
--- FAIL: TestSum (0.00s)
    calc_test.go:11: sum(4,9) should be 13, but doesn't match
FAIL
coverage: 50.0% of statements
FAIL    _/Users/bob/calc    0.011s
joji
I worked in Philippines and work in Tokyo.
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away