4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Goでtestをシリアル実行する

Posted at

結構ハマったのでメモ。

Goのテストはパッケージ単位で実行される。
glideを使っている場合、glide novendorでプロジェクト内のvendorディレクトリ以外のパッケージ一覧を返してくれるので

$ go test $(glide novendor)

とすることで、自分が作ったパッケージを全てテストに流すことができる。

ただ、このテストはデフォルトではCPUの数だけパッケージ単位でパラレルで実行される。
自分はテスト内でDBを使用し、データを消したりしていたためたまにテストが失敗するようになってしまった。
シリアルに実行するためには-pオプションを使う

	-p n
		the number of programs, such as build commands or
		test binaries, that can be run in parallel.
		The default is the number of CPUs available.
$ go test -p=1 $(glide novendor)

-parallelというオプションがあるが、これはテスト内でt.Parallel関数を使って並列化する時に使うらしい。

4
1
0

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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?