JUnit 4: how to get test name inside a Rule? e.g.,
public class MyRule extends ExternalResource {
@Before
public void before() {
// how to get the test method name to be run?
}
}
JUnit 4: how to get test name inside a Rule? e.g.,
public class MyRule extends ExternalResource {
@Before
public void before() {
// how to get the test method name to be run?
}
}
If you just need a
@Rulewith the test name, don't reinvet the wheel, just use the built-inTestName@Rule.If you're trying to build your own rule that adds some logic to it, consider extending it. If that isn't an option either, you could just copy it's implementation.
To answer the question in the comment, like any other
TestRule,ExternalResoucealso has anapply(Statement, Description)method. You can add functionality to it by overriding it, just make sure you call the super method so you don't break theExternalResourcefunctionality: