3
2

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 3 years have passed since last update.

JUnit4+Kotlinでのパラメータテストの書き方

3
Posted at

パラメータを生成するメソッドがStaticメソッドである必要があるのでJvmStaticにする必要があった

@RunWith(Parameterized::class)
internal class ParameterTest(
    val case: TestCase
) {
    data class TestCase(
        val param: Param,
        val expect: Expect
    ) {
        // テストケースのパラメータを定義する
        data class Param(
            val parameter: Parameter
        )

        // テストケースの期待値
        data class Expect(
            val value: String
        )
    }

    companion object {
        @JvmStatic
        @Parameters
        fun params() = listOf(
            TestCase(
                param = TestCase.Param(),
                expect = TestCase.Expect("dummy")
            )
        )
    }

    @Test
    fun test_param() {
        val act = TestTarget(
            param = case.param.parameter,
        )

       assertThat(act).isEqualTo(case.expect.value)
    }
}
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?