共生体 / silverstripe-test-assist
对默认SS测试结构的扩展,允许在CI构建中进行参数化,同时提供了一个Selenium测试框架。
Requires
- codeception/codeception: ~2.3
- phpunit/phpunit: ^5.7
- silverstripe/framework: ~4.0
Replaces
- dev-master / 4.1.x-dev
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.1
- 4.0.0
- 3.0.x-dev
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.7.x-dev
- 1.7.1
- 1.7.0
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.x-dev
- 1.2.1
- 1.2.0
- 1.1.x-dev
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.x-dev
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-legacy
This package is auto-updated.
Last update: 2024-08-27 12:01:45 UTC
README
向基本SilverStripe测试框架添加了几个助手,通过参数化几个配置选项,简化了将测试过程链接到CI服务器(如Jenkins)的过程。
此外,该模块还提供了SymbioteSeleniumTestCase
,它提供了一个更简单的API来编写由Selenium驱动的测试。
命令行参数
为了帮助测试执行,有几个参数可以用作在反复运行测试时加快速度。
build=0
- 在测试初始化期间不执行dev/buildclean=0
- 不要清除现有的数据库状态flush=0
- 在测试初始化期间不执行manifest flush
Selenium
要仅运行Selenium测试,可以使用如下命令行
php vendor/silverstripe/framework/cli-script.php dev/tests/module/test-assist \
flush=1 build=1 selenium_host=127.0.0.1 browser=firefox \
test_url=http://my.silverstripe.site/ test_type=SymbioteSeleniumTestCase SkipTests=symbioteseleniumtestcase \
admin_user=admin admin_pass=admin
注意:URL末尾的反斜杠很重要!
应该可以开始。请注意,您需要必须运行selenium服务器才能使其工作。以下命令将启动selenium服务器在虚拟帧缓冲区中,这意味着窗口不会散布到整个屏幕!
#!/bin/sh
/usr/bin/xvfb-run -e /var/log/selenium/xvfb-selenium.log -n 10 \
-s "-screen 10 1024x768x8" \
java -jar /home/path/to/programs/selenium-server-standalone-2.39.0.jar \
-port 4444 -log /var/log/selenium/server.log
但是,将selenium服务器直接从命令行运行可能会很有用,以便调试测试失败的原因。
诊断工具
在您的DB配置中将MySQLDatabase更改为DevMySQLDatabase
--- Name: dev_filters --- Injector: RequestProcessor: properties: filters: - %$QueryDisplayFilter - %$RequestTimerFilter
Codeception
要为项目连接Codeception,您需要在项目顶级创建一个codeception.yml配置文件。
include:
- mymodule/codeception
paths:
log: path/to/logdir
codeception.yml定义了测试运行中要包含的模块的路径。
在您的模块中,您可以在顶级路径中创建一个特定于项目的测试集合,然后将其包含在内。
- mkdir modulename/codeception
- cd modulename/codeception
- ../../vendor/bin/codecept bootstrap --namespace modulenamespace
- mv codeception.yml codeception.dist.yml
- touch .gitignore
注意,“modulenamespace”可以是任何东西,只要它是有效的PHP命名空间字符串即可
接下来,创建一个新的codeception.yml
文件,其中只包含您本地环境的codeception配置;这通常将是开发测试的本地URL,即
modules:
config:
WebDriver:
url: http://project.clients.sslocal
browser: chrome
更新modulename/codeception/tests/functional.suite.xml
并添加几个模块
class_name: FunctionalTester
modules:
enabled:
- \modulename\Helper\Functional
- WebDriver # new
- \Symbiote\TestAssist\SilverstripeFunctional # new
更新modulename/codeception/tests/_bootstrap.php
以包含SilverstripFunctional助手
<?php
// This is global bootstrap for autoloading
include_once 'test-assist/code/codeception/SilverstripeFunctional.php';
更新modulename/codeception/tests/unit/_bootstrap.php
以设置单元测试的环境
<?php
// Unit testing specific setup
include_once 'vendor/silverstripe/framework/tests/bootstrap.php';
现在,将以下内容添加到.gitignore
codeception.yml
/tests/_output/
将您的模块包含在顶级的codeception.yml
include:
- modulename/codeception
最后,开始编写测试!在modulename/codeception/tests/functional/FirstTestCept.php
<?php
use \Codeception\Util\Locator;
$I = new \modulenamespace\FunctionalTester($scenario);
$I->wantTo("Test the homepage");
$I->amOnPage("/");
$I->see("Home");
在modulename/codeception/tests/unit/SmokeTest.php
<?php
class PageTest extends SapphireTest {
public function testMyMethod() {
$this->assertEquals(2, Page::MyMethod());
}
}
从项目顶级开始
$ ./vendor/bin/codecept run
关于更好的按钮的说明
如果已安装了更好的按钮,则一些内置的助手方法将无法正常工作。如果是这种情况,请在codeception.dist.yml中添加
\Symbiote\TestAssist\SilverstripeFunctional.use_better_buttons: true