Skip to content

Instantly share code, notes, and snippets.

@cortinico
Created November 27, 2018 15:16
Show Gist options
  • Save cortinico/7a65aa2b05a72ae00624007a0ea4616d to your computer and use it in GitHub Desktop.
Save cortinico/7a65aa2b05a72ae00624007a0ea4616d to your computer and use it in GitHub Desktop.
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