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.                             
CommentFileSizeAuthor
drush simpletest one.patch4.31 KBBevan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

Status: Needs review » Postponed (maintainer needs more info)

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

Bevan’s picture

Title: Run one simplestest case. » Command to run one simplestest on command line

10 good reasons to use this instead simpletest's run-tests.php, and include it in drush;

  1. run-tests.sh has no documentation (that I could find – and I looked)
  2. run-tests.sh is complex enough to need documentation
  3. run-tests.sh is yet another freakin tool to learn
  4. drush test is simple
  5. drush test is self-documenting by the nature of drush
  6. drush test doesn't need additional documentation
  7. drush test is way more convenient when you are writing tests (as opposed to running them in bulk)
  8. drush test will run anywhere drush is working and simpletest is installed – no extra config or installation
  9. drush test is designed for the test-writer/developer
  10. drush test is discoverable via drush
Dave Reid’s picture

+1 for this living in drush. run-tests.sh has never worked properly for me.

greg.1.anderson’s picture

Status: Postponed (maintainer needs more info) » Active

Whatever happened to the drush simpletest stuff? It's gone now?

Perhaps this can be closed out if a decision was definitely made.

Dave Reid’s picture

Sadness. :(

moshe weitzman’s picture

There is hope!

I would like to see http://github.com/yhahn/drush_test ported to D7 and included in core drush.

greg.1.anderson’s picture

Maybe this issue should move on over to D7 core; evangelise for the conversion of run-tests.sh to run-tests.drush.inc.

hiddentao’s picture

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

langworthy’s picture

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

Bevan’s picture

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

moshe weitzman’s picture

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

langworthy’s picture

Sorry 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?

Bevan’s picture

Status: Active » Closed (won't fix)

Run-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. :(

moshe weitzman’s picture

Title: Command to run one simplestest on command line » Command to run simpletests
Status: Closed (won't fix) » Active

Re-opening since I'd still like someone to polish yhahn's work. See #6.

yhahn’s picture

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

langworthy’s picture

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

hiddentao’s picture

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

Bevan’s picture

Component: Code » PM (dl, en, up ...)

I've moved the original feature this issue was for to #927126: Drush command to run one single simpletest.

langworthy’s picture

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

langworthy’s picture

The error I'm receiving is actually the same as Bevan was getting in #1 of #927126: Drush command to run one single simpletest

langworthy’s picture

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

langworthy’s picture

Status: Active » Needs review

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

langworthy’s picture

When using the minimal profile in HEAD installed using drush site-install and running drush test with the --root flag, XMLRPCBasicTestCase has 1 failure. No failure without --root flag.

moshe weitzman’s picture

Status: Needs review » Fixed

Very 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

Status: Fixed » Closed (fixed)

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