Instantly share code, notes, and snippets.

Embed
What would you like to do?
Just a stupid JUnit rule that prints before and after executing a statement
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
class PrintRule(val label: String) : TestRule {
override fun apply(statement: Statement, description: Description): Statement {
return object : Statement() {
override fun evaluate() {
println("$label before statement")
try {
statement.evaluate()
} finally {
println("$label after statement")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment