跳转到主要内容
gokookie 提交于 3 May 2012

原文链接http://drupal.org/node/645286

命令行执行测试--linux平台

本章节供那些希望或者需要命令行来运行测试套件者阅读。这方法会经常用到在,比如当想整合第三方系列工具,的时候。当你只希望做小规模的,测试一个或几个模块式式,我希望本页面能收集测试方面的信息和技巧。

对于想通过GUI来运行SImpletest的开发者,请阅读Simpletest指南 ; 深入阅读指南,你会发现通过Durpal用户界面来运行测试的一些信息。通过drupal界面以命令行访问Simpletest的两个重要链路是admin/config/development/testing/ and admin/config/development/testing/results。

位于/scripts下有个run-tests.sh的帮助文件,它使在Drupal中,通过命令行执行测试变得非常容易。你可以作为web服务器端用户,去站点的根目录下,执行php scripts/run-tests.sh,就可以很容易地执行测试套件。

如果你不喜欢每次都输入/scripts/run-test.sh,在你的路径下如果存在bin目录,则可以在~/bin目录下建一个symlink符号连接,如下显示:

ln -s scripts/run-tests.sh ~/bin

运行不带参数的脚本可以弹出帮助页面,并给出option列表。

下面我们来全面地展开run-scripts.sh:

www-data@dev:/var/www-drupal-7-head$ php scripts/run-tests.sh Run Drupal tests from the shell. Usage: run-tests.sh [OPTIONS] Example: run-tests.sh Profile All arguments are long options. --help Print this page. --list Display all available test groups. --clean Cleans up database tables or directories from previous, failed, tests and then exits (no tests are run). --url Immediately preceeds a URL to set the host and path. You will need this parameter if Drupal is in a subdirectory on your localhost and you have not set $base_url in settings.php. --php The absolute path to the PHP executable. Usually not needed. --concurrency [num] Run tests in parallel, up to [num] tests at a time. This requires the Process Control Extension (PCNTL) to be compiled in PHP, not supported under Windows. --all Run all available tests. --class Run tests identified by specific class names, instead of group names. --file Run tests identified by specific file names, instead of group names. Specify the path and the extension (i.e. 'modules/user/user.test'). --xml If provided, test results will be written as xml files to this path --color Output the results with color highlighting. --verbose Output detailed assertion messages in addition to summary. [,[, ...]] One or more tests to be run. By default, these are interpreted as the names of test groups as shown at ?q=admin/config/development/testing. These group names typically correspond to module names like "User" or "Profile" or "System", but there is also a group "XML-RPC". If --class is specified then these are interpreted as the names of specific test classes whose test methods will be run. Tests must be separated by commas. Ignored if --all is specified. To run this script you will normally invoke it from the root directory of your Drupal installation as the webserver user (differs per configuration), or root: sudo -u [wwwrun|www-data|etc] php ./scripts/run-tests.sh --url http://example.com/ --all sudo -u [wwwrun|www-data|etc] php ./scripts/run-tests.sh --url http://example.com/ --class UploadTestCase

用Drush来实现命令行执行测试--Linux平台

Drush后面跟一些命令可以来协助测试:

drush test mail : 运行测试套件,将结果发送到站点邮件. drush test clean: 清除测试套件表和遗留的文件. drush test drush : 测试drush (似乎只对drush有效)。

请阅读代码。本页浅表性地介绍地执行测试的脚本可以扩展,并可按自己的想法重复使用。

友好建议:

  • 确保你是以web服务器端用户来运行测试。
  • 如果你是通过远程shell在CLI上运行测试,screen(1) 实用工具对于长时间的测试会话很有效
  • Xdebug扩展可能和有些测试有冲突。
  • 或者禁用Xdebug,或在php.ini文件中[xdebug]下添加 xdebug.max_nesting_level=500.

命令行执行测试--Windows平台

Windows用户没有现成的.bat文件来容易地实现命令行测试。我认为编译一个.bat文件或安装cygwin来运行linux指令会更容易些。欢迎Windows开发者们来更新本章节,介绍最合适在windows平台使用的命令行测试。