LoginSignup
3
2

More than 3 years have passed since last update.

ScalaでPowerAssertを使う

Posted at

DiagrammedAssertionsを紹介する記事がQiitaにないことに気付いたので書いておこうと思いました。

ScalaにExpectyというpower assertのライブラリがありますが、
(参考:Expecty を用いた power assert を復活させる)
Scalatestを使っている場合は、Expectyを使わなくてもDiagrammedAssertionsでpower assertできます。

import org.scalatest.{DiagrammedAssertions, FunSpec}

class ExampleSpec extends FunSpec with DiagrammedAssertions {
  it("example") {
    assert(2 * 3 === 5)
  }
}
> ExampleSpec:
> - example *** FAILED ***
>   assert(2 * 3 === 5)
>            |   |   |
>            6   |   5
>                false (ExampleSpec.scala:7)

細かい使い方はDiagrammedAssertionsのScalaDocを見るといいです。

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