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

kotestでなんで引数にinit{}の中身にいれられるの?(豆知識)

Posted at

Q: kotestを使ってテストを書く時、以下のようにinit{}を用いて書くことができますが、

class Test : DescribeSpec() {
    init {
        describe("test") {
            it("test") {
                println("test")
            }
        }
    }
}

以下のように引数にいれることでインデントを1段階浅くすることができます。

class Test : DescribeSpec({
    describe("test") {
        it("test") {
            println("test")
        }
    }
}) 

A: なぜこのようなことができるかというと、以下で引数にblockを渡すとinit内で実行できるという実装がkotest側で行われているからです。

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