Problem/Motivation
Quite often you want to only run a single method from a test.
Steps to reproduce
Allow method names to be appended to the class name. For example if we want to run the testBlockVisibility test in BlockTestCase we pass the following class argument to run-tests.sh
--class 'BlockTestCase::testBlockVisibility'
Proposed resolution
Backport from D8: #2390749: run-tests.sh should allow single test methods to be run
Remaining tasks
Backport
- Review and Test
- Write change record?
User interface changes
None
API changes
run-tests.sh: added support for running a single test method, e.g.--class "TestClass::testMethod"
Data model changes
Release notes snippet
run-tests.sh: added support for running a single test method, e.g.--class "TestClass::testMethod"
Comments
Comment #2
jedihe commentedI'm uploading patch #21 from #2390749: run-tests.sh should allow single test methods to be run.
This patch was worked out by:
- @pietmarcus
- @David_Rothstein
- @Berdir
- @mikran
- @jedihe
Tested scenarios:
- run-tests.sh ... MyTestGroup: detects all classes, and runs them
- run-tests.sh ... --class MyTestClass: runs only the test methods in the specified class
- run-tests.sh ... --class MyTestClass::testMethod: runs only the specified test method
- run-tests.sh ... --class 'PathTestCase,BlockTestCase::testBlockVisibility': runs all test methods in PathTestCase, runs only ::testBlockVisibility from BlockTestCase.
Comment #3
jedihe commentedComment #4
jedihe commentedComment #5
damienmckennaCore maintainers - what requirements do you have in order to get this committed? Thank you.
Comment #6
damienmckennaComment #7
mcdruid commentedIt'd be amazing to be able to run specific methods from classes! Definitely +1
However, it looks like the patch needs a reroll?
Comment #8
jedihe commentedComment #9
jedihe commentedHere's a quick reroll. Not yet tested.
Comment #10
jedihe commentedJust ran a quick test for:
- run-tests.sh ... --class 'PathTestCase,BlockTestCase::testBlockVisibility'
It worked as expected: all test methods* for PathTestCase were detected and executed, only BlockTestCase::testBlockVisibility() was executed for that test class.
When I tried --cache-modules, it ran correctly, but comparing timings of first vs. second execution didn't really show improvement.
*: didn't check against the .php file itself.
Comment #11
mcdruid commentedThank you; I think this looks good.
I've done a bit of manual testing and it all seems to work as expected.
There are a couple of quirks like this:
...where ideally the summary would show which results correspond to each specific method.
However, I don't think that should block us getting this in. More details are available from the verbose output.
Comment #12
mcdruid commentedI forgot to mention that there's a whitespace issue in the comment at the start of the file (is it a tab being introduced?) in the patch.
That can be fixed on commit.
Comment #13
fabianx commentedLet's use a different variable name at least, it's confusing to have first test_class and then class_name and then the other way round.
Maybe as it's our loop just rename class_name to test_class first and then use the usual variable name.
It's a nit, but it confused me in code review.
Besides that: RTBC + 1
Comment #14
mcdruid commentedSmall tweak to the variable names as they were a bit confusing.
Comment #19
mcdruid commentedAdding credit from original issue per #2.
Comment #21
mcdruid commentedThank you!
Comment #22
damienmckennaThanks for finishing it off and the quick commit, mcdruid, and Fabianx thanks for the review!
Comment #23
mcdruid commented