2
0

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.

ScalaTestでテストケースを指定する。

Posted at

TL;DR

sbt 'testOnly **.WhatYouWantToTest -- -z "someMethod should"' のように指定してやると、
テストクラス WhatYouWantToTest の中で someMethod についてのテストケースのみ走らせることが出来る。
(今回はFlatSpec利用を想定していますので、他の記法を利用している場合は -z で指定する文字列は適宜調整してください)

ScalaTestで、テストクラス内の特定のテストケースのみを走らせたい

FlatSpecで以下のようなテストメッセージが出るものを想定した際、 someMethod に対応したテストケースのみテストしたいとします。

someMethod
- should なんかやります1
- should なんかやります2
- should なんかこの時は駄目です1
- should こういうときは限界だとエラーを吐きます。
fugaMethod
- should hogehoge1
- should fugafuga
 :

その際は sbt 'testOnly **.WhatYouWantToTest -- -z "someMethod should"' のように、
-z にわたす文字列に someMethod should と指定してやれば、 上のメッセージにおいて

someMethod
- should なんかやります1
- should なんかやります2
- should なんかこの時は駄目です1
- should こういうときは限界だとエラーを吐きます。

に該当する箇所のみテストが走ります。(上はFlatSpecでのテスト例になります。他の記法では適宜文言を調整してください)

補足

ScalaTestで特定のテストクラスをテストする。

sbt 'testOnly org.example.HogeSpec'
sbt 'testOnly org.example.*'
sbt 'testOnly **.HogeSpec' というような指定の仕方をしてやればよい。12

特定のテストクラス内の特定のテストケースのみを走らせたい

どうやら、 -- の次に好きなオプションを指定できるらしい。2

you can also pass arguments for individual runs by using test-only and placing them after --, like this:

選択可能なオプション3の中でテストケース指定に便利そうなのは、 -z オプション1であり、

上で述べたように、 sbt 'testOnly **.WhatYouWantToTest -- -z "someMethod should"' というふうに、
ScalaTestの記法にマッチさせるようにしてやるとより便利です。

  1. https://qiita.com/suin/items/0294a53d6babd69f29a9 2

  2. http://www.scalatest.org/user_guide/using_scalatest_with_sbt 2

  3. http://www.scalatest.org/user_guide/using_the_runner

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?