Last active
January 10, 2023 10:56
-
-
Save weixinfree/00707f3649d40b8d93de6febda6c7158 to your computer and use it in GitHub Desktop.
kotlin test routine 封装 given,when,then
This file contains hidden or 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 <T> given(desc: String = "", block: () -> T): TestRoutine<T> { | |
| return TestRoutine("given: $desc", block) | |
| } | |
| class TestRoutine<T>( | |
| private val message: String = "", | |
| private val block: () -> T | |
| ) { | |
| fun <R> when_(desc: String = "", whenBlock: (T) -> R): TestRoutine<R> { | |
| val block = { whenBlock(block()) } | |
| return TestRoutine("$message\nwhen: $desc", block) | |
| } | |
| fun then(desc: String = "", assertBlock: (T) -> Unit) { | |
| assertBlock(block()) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment