LoginSignup
0

More than 5 years have passed since last update.

goconveyでsetUp, tearDownのタイミングを理解する

Last updated at Posted at 2018-05-23

概要

Goのテストツールであるgoconveyを雰囲気理解で使用しているので、setUptearDownな処理をするために
どう記述するのがいいのか確認したのでメモ。

conv_test.go
package sample

import (
    "testing"

    "fmt"

    . "github.com/smartystreets/goconvey/convey"
)

func TestConvey(t *testing.T) {
    Convey("テストケース", t, func() {

        fmt.Println("setUp")

        Convey("テストA", func() {
        })

        Convey("テストB", func() {
        })

        Reset(func() {
            fmt.Println("tearDown")
        })
    })
}

実行結果

verboseオプション付きで実行

$ go test -v sample/conv_test.go   

出力結果 (少し整形)

=== RUN   TestConvey

  テストケース

setUp

    テストA tearDown
setUp

    テストB tearDown



0 total assertions

fmt.Println("setUp")で出力した通りにsetUp処理をして、tearDownはReset()で行う。
これで事前処理、事後処理が出来る。

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0