我有一个测试套件,其中有20个羽毛文件和100%的MySQL CRUD操作正在执行。大约需要5分钟才能完成。如果我手动做测试,最多需要7分钟。我需要知道的是,我需要做什么来优化整个过程?
Note:Behat 3的ParallelRunnder 不支持,所以现在它超出了范围!
如果您打算建议使用Behat 3,那么请帮助我修改我的composer.json & behat.yml文件,因为当我自己操作并运行bin/behat时,会出现以下错误:
`Behat\Symfony2Extension\Extension` extension file or class could not be located.
`Behat\MinkExtension\Extension` extension file or class could not be located.
Unrecognized options "mink_driver" under "testwork.symfony2"
Unrecognized options "context, paths" under "testwork" 正如你在下面看到的,我使用的是特定的数字,没有星号。
CURRENT composer.json:
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.5.4",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0",
"sensio/framework-extra-bundle": "~3.0",
"incenteev/composer-parameter-handler": "~2.0",
"behat/behat": "2.5.3",
"behat/behat-bundle": "1.0.0",
"behat/symfony2-extension": "1.1.2",
"behat/mink": "1.5.0",
"behat/mink-extension": "~1.3",
"behat/mink-selenium2-driver": "1.1.1",
"behat/mink-goutte-driver": "1.0.9"
},CURRENT behat.yml:
default:
context:
class: FeatureContext
parameters:
output_path: %behat.paths.base%/build/behat/output/
screen_shot_path: %behat.paths.base%/build/behat/screenshot/
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
base_url: 'http://symfony.local/app_test.php/'
files_path: %behat.paths.base%/build/dummy/
javascript_session: selenium2
browser_name: firefox
goutte: ~
selenium2: ~
paths:
features: %behat.paths.base%/src
bootstrap: %behat.paths.features%/Context编辑
我有20个特性文件和一个场景在每一个。关于CRUD操作:
pdo_mysql作为database_driverFeatureContext文件的一部分:
namespace Site\CommonBundle\Features\Context;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\Symfony2Extension\Context\KernelAwareInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Process\Process;
/**
* Class FeatureContext
*
* Parent to other FeatureContext files. It is used to avoid duplicated codes and all the
* shared commons are kept here.
*
* @package Site\CommonBundle\Features
*/
class FeatureContext extends MinkContext implements KernelAwareInterface
{
protected $kernel;
protected $screenShotPath;
protected $outputPath;
/**
* Parameter $parameters comes from behat.yml file.
* @param array $parameters
*/
public function __construct(array $parameters)
{
$this->outputPath = $parameters['output_path'];
$this->screenShotPath = $parameters['screen_shot_path'];
}
/**
* Helps to use doctrine and entity manager.
* @param KernelInterface $kernelInterface Interface for getting Kernel.
*/
public function setKernel(KernelInterface $kernelInterface)
{
$this->kernel = $kernelInterface;
}
/**
* Without this, PhantomJs will fail if responsive design is in use.
* @BeforeStep
*/
public function resizeWindow()
{
$this->getSession()->resizeWindow(1440, 900, 'current');
}
/**
* Take screen-shot when step fails. Works only with Selenium2Driver.
*
* @AfterStep
* @param $event Current event.
* @throws \Behat\Mink\Exception\UnsupportedDriverActionException
*/
public function takeScreenshotAfterFailedStep($event)
{
if (4 === $event->getResult()) {
$driver = $this->getSession()->getDriver();
if (! ($driver instanceof Selenium2Driver)) {
throw new UnsupportedDriverActionException(
'Taking screen-shots is not supported by %s, use Selenium2Driver instead.',
$driver
);
return;
}
if (! is_dir($this->screenShotPath)) {
mkdir($this->screenShotPath, 0777, true);
}
$filename = sprintf(
'%s_%s_%s.%s',
$this->getMinkParameter('browser_name'),
date('Ymd') . '-' . date('His'),
uniqid('', true),
'png'
);
file_put_contents($this->screenShotPath . '/' . $filename, $driver->getScreenshot());
}
}
/**
* @When /^I login as "([^"]*)"$/
* @param $type User role type.
*/
public function iLoginAs($type)
{
$container = $this->kernel->getContainer();
$userData = $container->getParameter('dummy_user');
$this->visit('/login');
$this->fillField('username', $userData[$type]['username']);
$this->fillField('password', $userData[$type]['password']);
$this->pressButton('_submit');
}
.........
}发布于 2014-10-16 17:45:19
我不知道为什么我认为它需要20分钟才能运行,可能会把它与功能的数量混淆起来。5分钟一点也不坏。有一些基本的事情,你可以做,可以帮助加快它。
@BeforeStep内部的逻辑--您可能可以将其迁移到@BeforeScenario,甚至@BeforeFeature,甚至@BeforeSuite --没有必要这么频繁地这样做。iLoginAs可能在每个步骤中都使用。通过手动创建用户会话并将cookie设置为标头,您可以更快地更新它,即身份验证方法中的相同逻辑进入步骤定义,然后只需执行$this->getSession()->getDriver()->setCookie(session_name(), session_id()); --在下一个请求上,您的用户已经通过了身份验证。browser_name: firefox -上帝没有…使用chrome,它必须更快。发布于 2014-10-17 12:55:27
我将在这里公布上述所有建议后的结果,让其他人看看它们是如何解决的,所以每次我介绍一个步骤时,我都会更新这个帖子。
原始时间:
Total time: 4 minutes 12.55 seconds实现步骤1后的时间:
Total time: 2 minutes 8.01 seconds注意:由于OOP中不允许访问静态方法中的$this密钥,所以只有@BeforeScenario才能工作,因为@BeforeFeature和@BeforeSuite要求resizeWindow()是静态的。如果有可能,结果会快得多。
实现步骤2后的时间:
注意:请阅读下面的步骤6。
实现步骤3后的时间:
注意:我是一个Symfony2用户,不幸的是我没能实现这一点。
实现步骤4后的时间:
Total time: 1 minutes 54.11 seconds注意: Behat 3用户-使用java -jar selenium-server-standalone-2.43.1.jar -Dwebdriver.chrome.driver="chromedriver"运行selenium
实现步骤6后的时间:
Total time: 0 minutes 52.04 seconds注意: Symfony2用户--如果您将default_session设置为symfony2,则与goutte和selenium2相比,它的出血速度更快。Goutte: 1分20.03秒,Selenium2: 1分31.00秒
https://stackoverflow.com/questions/26409202
复制相似问题