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

jedihe created an issue. See original summary.

jedihe’s picture

I'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.

jedihe’s picture

Status: Active » Needs review
jedihe’s picture

Issue summary: View changes
damienmckenna’s picture

Core maintainers - what requirements do you have in order to get this committed? Thank you.

damienmckenna’s picture

mcdruid’s picture

Issue tags: +Needs reroll

It'd be amazing to be able to run specific methods from classes! Definitely +1

However, it looks like the patch needs a reroll?

jedihe’s picture

Assigned: Unassigned » jedihe
jedihe’s picture

Assigned: jedihe » Unassigned
Issue tags: -Needs reroll
StatusFileSize
new3.55 KB

Here's a quick reroll. Not yet tested.

jedihe’s picture

Just 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.

mcdruid’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs manual testing, +Pending Drupal 7 commit

Thank 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:

Tests to be run:
 - User login (UserLoginTestCase::testPerUserLoginFloodControl)
 - User login (UserLoginTestCase::testLoginWithAnonSession)

...snip...

Test summary
------------

User login 64 passes, 0 fails, 1 exception, and 20 debug messages
User login 10 passes, 0 fails, 0 exceptions, and 3 debug messages

...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.

mcdruid’s picture

I 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.

fabianx’s picture

+++ b/scripts/run-tests.sh
@@ -598,7 +617,12 @@ function simpletest_script_reporter_init() {
-      $info = call_user_func(array($class_name, 'getInfo'));
+      if (strpos($class_name, '::') > 0) {
+        list($test_class, $method) = explode('::', $class_name, 2);
+        $info = call_user_func(array($test_class, 'getInfo'));
+      } else {
+        $info = call_user_func(array($class_name, 'getInfo'));
+      }

Let'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

mcdruid’s picture

StatusFileSize
new867 bytes
new3.66 KB

Small tweak to the variable names as they were a bit confusing.

mcdruid credited Berdir.

mcdruid credited mikran.

mcdruid’s picture

Adding credit from original issue per #2.

  • mcdruid committed 9f42db5 on 7.x
    Issue #3209417 by jedihe, mcdruid, DamienMcKenna, Fabianx, Berdir,...
mcdruid’s picture

Status: Reviewed & tested by the community » Fixed

Thank you!

damienmckenna’s picture

Thanks for finishing it off and the quick commit, mcdruid, and Fabianx thanks for the review!

mcdruid’s picture

Issue tags: -Pending Drupal 7 commit

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.