Last active
October 2, 2019 02:29
-
-
Save lusingander/e244377168e92f4f9f46ab718092cdfd to your computer and use it in GitHub Desktop.
Kotlin + JUnit5 + Nested classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun value(str: String): Int { | |
println(str) | |
return 0 | |
} | |
fun test(str: String) { | |
println("【Executed Test: $str】") | |
} | |
class Test1 { | |
constructor() { | |
println("Test1 constructor called") | |
} | |
val v1_1 = value("v1_1") | |
companion object { | |
@BeforeAll @JvmStatic | |
fun beforeAll() = println("@: Test1 BeforeAll") | |
} | |
@BeforeEach | |
fun beforeEach() = println("@: Test1 BeforeEach") | |
@Test | |
fun test1_1() = test("test1_1") | |
@Test | |
fun test1_2() = test("test1_2") | |
@Nested | |
inner class Test2 { | |
constructor() { | |
println("Test2 constructor called") | |
} | |
val v2_1 = value("v2_1") | |
val v2_2 = value("v2_2") | |
val v2_3 by lazy { value("v2_3 (by lazy)") } | |
@Test | |
fun test2_1() = test("test2_1") | |
@Test | |
fun test2_2() { | |
test("test2_2") | |
v2_3 | |
} | |
@Test | |
fun test2_3() { | |
test("test2_3") | |
v2_3 | |
} | |
} | |
@Nested | |
inner class Test3 { | |
constructor() { | |
println("Test3 constructor called") | |
} | |
val v3_1 = value("v3_1") | |
@Test | |
fun test3_1() = test("test3_1") | |
@Nested | |
inner class Test4 { | |
constructor() { | |
println("Test4 constructor called") | |
} | |
val v4_1 = value("v4_1") | |
@Test | |
fun test4_1() = test("test4_1") | |
} | |
} | |
} | |
// => | |
// @: Test1 BeforeAll | |
// v1_1 | |
// Test1 constructor called | |
// @: Test1 BeforeEach | |
// 【Executed Test: test1_1】 | |
// v1_1 | |
// Test1 constructor called | |
// @: Test1 BeforeEach | |
// 【Executed Test: test1_2】 | |
// v1_1 | |
// Test1 constructor called | |
// v2_1 | |
// v2_2 | |
// Test2 constructor called | |
// @: Test1 BeforeEach | |
// 【Executed Test: test2_1】 | |
// v1_1 | |
// Test1 constructor called | |
// v2_1 | |
// v2_2 | |
// Test2 constructor called | |
// @: Test1 BeforeEach | |
// 【Executed Test: test2_2】 | |
// v2_3 (by lazy) | |
// v1_1 | |
// Test1 constructor called | |
// v2_1 | |
// v2_2 | |
// Test2 constructor called | |
// @: Test1 BeforeEach | |
// 【Executed Test: test2_3】 | |
// v2_3 (by lazy) | |
// v1_1 | |
// Test1 constructor called | |
// v3_1 | |
// Test3 constructor called | |
// @: Test1 BeforeEach | |
// 【Executed Test: test3_1】 | |
// v1_1 | |
// Test1 constructor called | |
// v3_1 | |
// Test3 constructor called | |
// v4_1 | |
// Test4 constructor called | |
// @: Test1 BeforeEach | |
// 【Executed Test: test4_1】 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment