gpt4 book ai didi

symfony - 如何在 Symfony2 中使用 Behat 和 Liip\FunctionalTestBundle?

转载 作者:行者123 更新时间:2023-12-04 12:40:09 24 4
gpt4 key购买 nike

我正在使用 Liip\FunctionalTestBundle 对于单元测试,它工作得很好。

AppCategoryControllerTest.php:

class AppCategoryControllerTest extends BoEditoAuthWebTestCase
{
public function setUp()
{
parent::setUp();

// It returns an array of class paths
$this->loadFixtures($this->getAllDataFixtures());
}
//...
}

现在我想在 Behat 中使用我的测试装置。

这怎么可能?

FeatureContext.php:
/**
* @BeforeScenario @createSchema
*
* load my fixtures with Liip\FunctionalTestBundle\Test\WebTestCase
*/
public function createDatabase()
{
// What can I do here?
}

最佳答案

由于这是一个 PHPUnit 测试用例,您不能直接在 Behat 中使用它。您需要在 Behat 上下文中复制该行为。

看看 SymfonyDoctrineContext来自 Behat/CommonContexts。这应该是一个很好的起点。上下文是为 Behat 2 编写的,因此您需要针对 Behat 3 对其进行调整。

I'm using Liip\FunctionalTestBundle for Unit testing, it works very well.



如果您使用的是 FunctionalTestBundle,那么您就不是在编写单元测试。单元测试是隔离的。功能测试是一种集成测试(不是孤立的)。如果您还没有注意到,这种测试既脆弱又缓慢。我建议您学习如何将更多的精力集中在真正的单元测试上。

关于symfony - 如何在 Symfony2 中使用 Behat 和 Liip\FunctionalTestBundle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34158978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com