0
1

More than 3 years have passed since last update.

Spockで強制的にエラー[Exception]を発生させる

Posted at
ServiceImpl
    def "異常系"() {
        setup:
//        service.createBody(_ as boolean) >> { throw new RuntimeException("dummy") }
        service.createBody(_) >> { throw new RuntimeException("dummy") }


        when:
        String testString = service.send(to, hash)

        then:
        RuntimeException e = thrown()
        e.getMessage() == expected

        where:
        testcase | to          | hash       | expected
        "test"   | "aaa@co.jp" | "testhash" | "dummy"

    }

IntelliJでservice.createBody(_)の_の部分が黄色くなってていつも補完してたけど
_だけならしっかりExceptionが発生してくれる。
booleanのときは特殊なのかな?
無理やりException発生させたいときは覚えておくと便利かも

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