You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know that we can use getTests() to get a list of all tests in a UnitTestCase, but I haven't been able to figure out if it's possible to access the test/method that's currently being run, setup, or checked for skipping.
The text was updated successfully, but these errors were encountered:
How to get the test/method that's currently being run?
You can get the test/method that's currently being run with __FUNCTION__.
If you need the name of the test class and the name of function, its
either get_class($this). '->' . __FUNCTION__ or simply echo __METHOD__.
Check also $this->getLabel(), which retruns get_class($this),
if the test name wasn't set to the test class in its constructor.
(But this is the class name of a test case - not the individual test method name.)
How to access the test/method during setUp()?
This isn't possible from a UnitTestCase.
The name of the next test method is basically $method inside SimpleInvoker,
but there is no easy way to access it from a UnitTestCase. One could possibly
come up with some Reflection based hacks to get access to $method in SimpleInvoker.
Thank you. This is as I suspected. I know how to get the name of the current function, but in my case I don't want to get skip or setUp, I wanted something like testNextTestToRun because (for various complicated reasons) I needed to run just a single test depending on some other factors. I was hoping to be able to do something like
function skip() {
$this->skipIf( $this->getCurrentTest() == "testNextTestToRun" );
}
In the end, I ended up overriding getTests() to return just the name of the test I wanted to run based on the "other factors" in play.
Thank you for the note about SelectiveReporter! I will have to have a look at it and how to use it.
I know that we can use
getTests()
to get a list of all tests in aUnitTestCase
, but I haven't been able to figure out if it's possible to access the test/method that's currently being run, setup, or checked for skipping.The text was updated successfully, but these errors were encountered: