Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This patch allows the user to run a single simpletest test case and get results on the command line. Example usage and output;
> drush
Execute a drush command. Run `drush help [command]` to view command-specific help.
Examples:
drush dl cck zen Download CCK module and Zen theme.
drush --uri=http://example.com status Show status command for the example.com multi-site.
drush help --pipe A space delimited list of commands
Options:
-r <path>, --root=<path> Drupal root directory to use (default: current directory)
-l <uri> , --uri=<uri> URI of the drupal site to use (only needed in multisite environments)
-v, --verbose Display extra information about the command.
-d, --debug Display even more information, including internal messages.
-q, --quiet Hide all output
-y, --yes Assume 'yes' as answer to all prompts
-s, --simulate Simulate all relevant actions (don't actually change the system)
-i, --include A list of paths to search for drush commands
-c, --config Specify a config file to use. See example.drushrc.php
-u, --user Specify a user to login with. May be a name or a number.
-b, --backend Hide all output and return structured data (internal use only).
-p, --pipe Emit a compact representation of the command for scripting.
Commands:
help Print this help message. Use --filter to limit command list to one command file (e.g.
--filter=pm)
cron Run all cron hooks.
updatedb Execute the update.php process from the command line
status Provides a birds-eye view of the current Drupal installation, if any.
script Run php script(s).
cache clear Clear all caches.
watchdog show Shows recent watchdog log messages. Optionally filter for a specific type.
watchdog delete Delete all messages or only those of a specified type.
sync Rsync the Drupal tree to/from another server using ssh.
eval Evaluate arbitrary php code after bootstrapping Drupal.
enable Enable one or more modules.
disable Disable one or more modules.
uninstall Uninstall one or more modules.
statusmodules Show module enabled/disabled status
refresh Refresh update status information
updatecode Update your project code
update Update your project code and apply any database updates required (update.php)
info Release information for a project
dl Download core Drupal and projects like CCK, Zen, etc.
test Run a specified test and outputs the results on the command line.
test mail Run all tests and mail the results to your team.
test clean Delete leftover tables and files from prior test runs.
sql conf Print database connection details.
sql connect A string for connecting to the DB.
sql dump Exports the Drupal DB as SQL using mysqldump.
sql query Execute a query against the site database.
sql load Copy source database to target database.
sql cli Open a SQL command-line interface using Drupalâs credentials.
coder Run code reviews
generate users Creates users.
generate taxonomy Creates taxonomy.
generate content Creates content.
soql show tables List tables in salesforce.
soql describe Describe an individual table in salesforce.
soql Execute a SOQL query.
> drush test
Available test cases
AdminMenuPermissionsTestCase
AdminMenuModulesTestCase
AdminMenuLinksTestCase
CapchaTestCase
CapchaAdminTestCase
CaptchaAdminTest
CABrandTest
CACiviMailTest
CACustomBlocksTest
CAErrorReportingTest
CAFilesTest
CAGoogleAnalyticsTest
CAHtaccessTest
CALipsumTest
CAModulesTest
CAPanelsTest
CAPerfTest
CASvnTest
CATinymceTest
CAUpdateStatusTest
CAViewsTest
CoderTestCase
CoderUpgrade6xTest
CoderCommentTest
CoderI18NTest
CoderSecurityTest
CoderSQLTest
CoderStyleTest
ContentCrudTestCase
ContentCrudBasicTest
ContentCrudSingleToMultipleTest
ContentCrudMultipleToSingleTest
ContentUICrud
ContentOptionWidgetTest
ContentProfileTest
ContentTaxonomyTestCase
ContentTaxonomyTest
ContentTaxonomyAutocompleteTest
ContentTaxonomyAutocompletePermissionsTest
DateAPITestCase
DateRepeatTestCase
FileFieldTestCase
FileFieldRevisionTestCase
FileFieldDisplayTestCase
FileFieldValidateTestCase
FileFieldPathTestCase
SignificantFiguresTestCase
GMapSimpleAPITest
GMapMacroTest
GoogleAnalyticsBasicTest
ImageCacheUrlTests
ImageFieldTestCase
ImageFieldDisplayTestCase
ImageFieldValidateTestCase
LinkContentCrudTest
MollomWebTestCase
MollomAccessTestCase
MollomFallbackTestCase
MollomUserFormsTestCase
MollomCommentFormTestCase
MollomContactFormTestCase
MollomResellerTestCase
PathRedirectUnitTest
PathRedirectPathautoUnitTest
PathRedirectFunctionalTest
PathautoTestCase
SimpleTestFunctionalTest
SimpleTestMailCaptureTestCase
BlockTestCase
TokenTestCase
WebformTestCase
WebformComponentsTestCase
WebformPermissionsTestCase
WebformSubmissionTestCase
> drush test FooBar
Test case FooBar not found. Perhaps you spelled it wrong or need to enable the module? [error]
Use the drush test command with no arguments to see a list of available test cases. E.g.
drush test
> drush test SignificantFiguresTestCase
64 tests passed.
> drush test SignificantFiguresTestCase
Status Message
pass Got 0 instead of 0 rounding 3450000 to 0 SF.
pass Got 3,000,000 instead of 3,000,000 rounding 3450000 to 1 SF.
pass Got 3,500,000 instead of 3,500,000 rounding 3450000 to 2 SF.
pass Got 3,450,000 instead of 3,450,000 rounding 3450000 to 3 SF.
pass Got 3,450,000 instead of 3,450,000 rounding 3450000 to 4 SF.
pass Got 3,450,000.0 instead of 3,450,000.0 rounding 3450000 to 8 SF.
pass Got 0 instead of 0 rounding 345 to 0 SF.
pass Got 300 instead of 300 rounding 345 to 1 SF.
pass Got 350 instead of 350 rounding 345 to 2 SF.
pass Got 345 instead of 345 rounding 345 to 3 SF.
pass Got 345.0 instead of 345.0 rounding 345 to 4 SF.
pass Got 345.00000 instead of 345.00000 rounding 345 to 8 SF.
pass Got 0 instead of 0 rounding 345.45 to 0 SF.
pass Got 300 instead of 300 rounding 345.45 to 1 SF.
pass Got 350 instead of 350 rounding 345.45 to 2 SF.
pass Got 345 instead of 345 rounding 345.45 to 3 SF.
pass Got 345.5 instead of 345.5 rounding 345.45 to 4 SF.
pass Got 345.45 instead of 345.45 rounding 345.45 to 5 SF.
pass Got 345.450 instead of 345.450 rounding 345.45 to 6 SF.
pass Got 0 instead of 0 rounding 0.345 to 0 SF.
pass Got 0.3 instead of 0.3 rounding 0.345 to 1 SF.
pass Got 0.35 instead of 0.35 rounding 0.345 to 2 SF.
pass Got 0.345 instead of 0.345 rounding 0.345 to 3 SF.
pass Got 0.3450 instead of 0.3450 rounding 0.345 to 4 SF.
pass Got 0.34500000 instead of 0.34500000 rounding 0.345 to 8 SF.
pass Got 0 instead of 0 rounding 0.00345 to 0 SF.
pass Got 0.003 instead of 0.003 rounding 0.00345 to 1 SF.
pass Got 0.0035 instead of 0.0035 rounding 0.00345 to 2 SF.
pass Got 0.00345 instead of 0.00345 rounding 0.00345 to 3 SF.
pass Got 0.003450 instead of 0.003450 rounding 0.00345 to 4 SF.
FAIL Got 0.00345000 instead of 0.0034000 rounding 0.00345 to 8 SF.
pass Got 0 instead of 0 rounding -3450000 to 0 SF.
pass Got -3,000,000 instead of -3,000,000 rounding -3450000 to 1 SF.
pass Got -3,500,000 instead of -3,500,000 rounding -3450000 to 2 SF.
pass Got -3,450,000 instead of -3,450,000 rounding -3450000 to 3 SF.
pass Got -3,450,000 instead of -3,450,000 rounding -3450000 to 4 SF.
pass Got -3,450,000.0 instead of -3,450,000.0 rounding -3450000 to 8 SF.
pass Got 0 instead of 0 rounding -345 to 0 SF.
pass Got -300 instead of -300 rounding -345 to 1 SF.
pass Got -350 instead of -350 rounding -345 to 2 SF.
pass Got -345 instead of -345 rounding -345 to 3 SF.
pass Got -345.0 instead of -345.0 rounding -345 to 4 SF.
pass Got -345.00000 instead of -345.00000 rounding -345 to 8 SF.
pass Got 0 instead of 0 rounding -345.45 to 0 SF.
pass Got -300 instead of -300 rounding -345.45 to 1 SF.
pass Got -350 instead of -350 rounding -345.45 to 2 SF.
pass Got -345 instead of -345 rounding -345.45 to 3 SF.
pass Got -345.5 instead of -345.5 rounding -345.45 to 4 SF.
pass Got -345.45 instead of -345.45 rounding -345.45 to 5 SF.
pass Got -345.450 instead of -345.450 rounding -345.45 to 6 SF.
pass Got 0 instead of 0 rounding -0.345 to 0 SF.
pass Got -0.3 instead of -0.3 rounding -0.345 to 1 SF.
pass Got -0.35 instead of -0.35 rounding -0.345 to 2 SF.
pass Got -0.345 instead of -0.345 rounding -0.345 to 3 SF.
pass Got -0.3450 instead of -0.3450 rounding -0.345 to 4 SF.
pass Got -0.34500000 instead of -0.34500000 rounding -0.345 to 8 SF.
pass Got 0 instead of 0 rounding -0.00345 to 0 SF.
pass Got -0.003 instead of -0.003 rounding -0.00345 to 1 SF.
pass Got -0.0035 instead of -0.0035 rounding -0.00345 to 2 SF.
pass Got -0.00345 instead of -0.00345 rounding -0.00345 to 3 SF.
pass Got -0.003450 instead of -0.003450 rounding -0.00345 to 4 SF.
FAIL Got -0.00345000 instead of -0.0034000 rounding -0.00345 to 8 SF.
pass Got 0 instead of 0 rounding 0 to 2 SF.
pass Got 0 instead of 0 rounding 0 to -2 SF.
Comment | File | Size | Author |
---|---|---|---|
drush simpletest one.patch | 4.31 KB | Bevan |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedThanks. I've gone back and forth about including simpletest runner in drush.
run-tests.sh is much more capable and is supported better (for d6 it is in simpletest project. in core for d7). Feel free to explain the reasoning, but for now I don't see much reason to duplicate it here.
Comment #2
Bevan CreditAttribution: Bevan commented10 good reasons to use this instead simpletest's run-tests.php, and include it in drush;
Comment #3
Dave Reid+1 for this living in drush. run-tests.sh has never worked properly for me.
Comment #4
greg.1.anderson CreditAttribution: greg.1.anderson commentedWhatever happened to the drush simpletest stuff? It's gone now?
Perhaps this can be closed out if a decision was definitely made.
Comment #5
Dave ReidSadness. :(
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedThere is hope!
I would like to see http://github.com/yhahn/drush_test ported to D7 and included in core drush.
Comment #7
greg.1.anderson CreditAttribution: greg.1.anderson commentedMaybe this issue should move on over to D7 core; evangelise for the conversion of run-tests.sh to run-tests.drush.inc.
Comment #8
hiddentao CreditAttribution: hiddentao commentedI've improved upon this patch such that it captures and outputs all exception logs, whilst providing verbosity and color output options. Most of the added code is lifted from run-tests.sh (which I couldn't get working either).
Latest code can always be downloaded from github (http://github.com/hiddentao/drush_simpletest_command). Please download or fork from there as you see fit.
Comment #9
langworthy CreditAttribution: langworthy commentedI may be missing something but the two CI suites I've tested (Hudson, CI Joe) require a non zero return value to fail. Both the solution in #6 and #8 don't seem to provide this. For example, when I look at the CLI output of Hudson I can see a list of any test failures, followed by a happy "Finished: SUCCESS".
I dropped an
exit (0);
within the code in #6 to solve the problem (and break drush). Does something need to change in these drush commands or am I not configuring my CI correctly?Comment #10
Bevan CreditAttribution: Bevan commentedThese run simpletests which test Drupal at the PHP layer with methods like assertTrue($variable). It has nothing to do with the command line exit status of drush.
Comment #11
moshe weitzman CreditAttribution: moshe weitzman commented@Bevan. Fpoks who use this command need a standard exit code in order to integrate with other tools like Hudson. Anyway, the patch here really isn't sufficient for drush. Someone needs to build on the work by yhahn that I mentioned in #6.
Comment #12
langworthy CreditAttribution: langworthy commentedSorry for going off-topic. Just a quick followup to #9. It's not the job of the test runner to properly exit, but for drush to.
@moshe, as per #6 is what you're looking for a D7 port, or more?
Comment #13
Bevan CreditAttribution: Bevan commentedRun-tests.php and this drush command are for different uses. This drush command was design to aid authors of simpletests — not automated build/testing systems like hudson. See comment #2 for more detail.
Clearly there is no support for it however. :(
Comment #14
moshe weitzman CreditAttribution: moshe weitzman commentedRe-opening since I'd still like someone to polish yhahn's work. See #6.
Comment #15
yhahn CreditAttribution: yhahn commentedI am picking this up again but haven't had a chance to jump into work on D7 compatibility yet. If you have a chance to do so please fork http://github.com/yhahn/drush_test on github and send pull requests, or patches work fine too.
Would love to hear a little more about
exit(0)
and whose responsibility it is to handle this?Comment #16
langworthy CreditAttribution: langworthy commentedyhahn: I chatted with adrian in #aegir a few days ago and he mentioned using drush_set_error(). Looks like you've implemented it on github.
Comment #17
hiddentao CreditAttribution: hiddentao commentedI needed to run the test scripts via ANT on Hudson.
Latest version of the patch (http://github.com/hiddentao/drush_simpletest_command) adds an 'error-on-fail' parameter which will cause the command to call
exit(-1)
if the test fails, thus allowing you to detect test failure from the command-line.Comment #18
Bevan CreditAttribution: Bevan commentedI've moved the original feature this issue was for to #927126: Drush command to run one single simpletest.
Comment #19
langworthy CreditAttribution: langworthy commentedI've done some basic work updating yhahn's drush_test to D7. https://github.com/sprice/drush_test/tree/7.x
Running with the --verbose flag it seems a single test begins to run well but then fails when trying to create an instance of a field.
Comment #20
langworthy CreditAttribution: langworthy commentedThe error I'm receiving is actually the same as Bevan was getting in #1 of #927126: Drush command to run one single simpletest
Comment #21
langworthy CreditAttribution: langworthy commentedI've tracked the problem to line 649 of modules/field/field.crud.inc
when using run-tests.sh, field_create_field() correctly initializes $field. test.drush.inc ends up with $field = 0 even though the bundle, entity_type and field_name properties are the same in each case (I used xdebug)
When commenting out some of the error checking for $field the tests with test.drush.inc finish but report exceptions (I tested using the XMLRPCBasicTestCase test class and got 5 passes, 0 fails, 4 exceptions. with run-tests.sh I received 5 passes, 0 fails, 0 exceptions)
Comment #22
langworthy CreditAttribution: langworthy commentedI filed a separate issue about the problems I was having #974768: test-run command fails using standard install profile. Seems to be a problem with the Standard profile. The latest code described in #19 is working great for me in D7 on a custom profile.
Comment #23
langworthy CreditAttribution: langworthy commentedWhen using the minimal profile in HEAD installed using
drush site-install
and runningdrush test
with the--root
flag, XMLRPCBasicTestCase has 1 failure. No failure without--root
flag.Comment #24
moshe weitzman CreditAttribution: moshe weitzman commentedVery nice work. This is passing just fine for me when using minimal install profile. Hopefully someone can track down that problem with standard profile.
I added docs, and modernized some.
Committed to HEAD.
In a new issue, I'd love to see us add JUnit style report format as per #602332: XML output option for use with Hudson / JUnit