Problem/Motivation
Quite often you want to only run a single method from a test.
Proposed resolution
Allow method names to be appended to the class name. For example if we want to run the testBookExport test in BookTest we pass the following class argument to run-tests.sh
--class 'Drupal\book\Tests\BookTest::testBookExport'
Remaining tasks
- Review
- Commit
User interface changes
None
API changes
None
Beta phase evaluation
| Unfrozen changes | Unfrozen because it only changes testing code |
|---|
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | 2390749-drupal-run-tests-single-method-21.patch | 3.2 KB | jedihe |
| #21 | 2390749-drupal-run-tests-single-method-21--interdiff.patch | 618 bytes | jedihe |
| #3 | 1-3-interdiff.txt | 851 bytes | alexpott |
| #1 | 2390749.1.patch | 2.12 KB | alexpott |
Comments
Comment #1
alexpottLet's stop commenting out code to run a single test method ftw.
Comment #2
dawehnerI really like that!
This line is really confusing, it would be great to document that.
Comment #3
alexpottSimplified it a bit.
Comment #4
dawehnerThat is great!
Comment #5
webchickThis seems like the kind of issue that'll only make it easier to get D8 done, so looks good to me. Unfortunately I don't believe it's possible to add automated tests for this.
Committed and pushed to 8.0.x. Thanks!
Comment #7
David_Rothstein commentedSeems like it could be backported, right?
Comment #9
pietmarcus commentedBackported to Drupal 7. Also cleaned up a minor code issue: function simpletest_script_get_test_list was called twice unnecessarily. The results of the first call were not re-used. In the drupal-8 version of the script this was already fixed.
Please review!
Comment #11
pietmarcus commentedTests ran successfully this time. Please review!
Comment #12
David_Rothstein commentedThe patch looks good and seems to work correctly.
The output it prints for "Tests to be run" is a little funny though (i.e. compared to running an entire class worth of tests):
Also the behavior is strange if you misspell the method name (especially compared to the existing behavior when you misspell the class name):
versus:
These are pretty minor issues however - do we know if they are fixed in Drupal 8? (If not, leaving them for a followup would be fine.)
And one small comment about the code:
Minor, but the comma isn't needed there - it could just be
list($class_name).Besides the above questions I think this should be RTBC.
Comment #13
berdirDrupal 8 doesn't have test names, it always only shows the class name in run-tests.sh and also the UI.
Not sure if what we should do for 7.x.
Comment #14
pietmarcus commentedI have updated the patch with the remarks of #12. Information should be better now for end-users.
Comment #15
mikran commented--class TestCase::testMethodworks but this patch breaks the original--class TestCase.Comment #18
mikran commentedThe patch didn't apply to latest core release. Rerolled.
Comment #21
jedihe commentedFixed the bug causing --class TestClass to fail.
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
Comment #22
jedihe commentedHad to manually cancel the tests, as this is not covered by tests.
Comment #23
jedihe commentedComment #24
jedihe commentedNoticed that earlier patches were checked by the testbot, so decided to re-test #21. Tests are passing, so this should be ready for review.
Comment #25
mradcliffeHi @jedihe. We used to do back ports in the same issue, but we should create a follow-up issue for your patch in Drupal 7 and then mark this as Fixed and change the version back.
Comment #26
jedihe commentedThanks @mradcliffe! I just filed the separate issue for the D7 backport. Marking this as fixed against 8.0.x-dev (latest 8.x I see used in this issue).