简体   繁体   English

是否有一种标准的方法来隔离Symfony2应用程序的单元和功能测试?

[英]Is there a standard way of segregating unit and functional tests for a Symfony2 app?

I have a Symfony2 app with unit and functional tests, and I wondered whether there was a usual practice to segregate unit and functional tests so that I don't have the overhead of compiling the configuration etc whenever I run the test suite? 我有一个带有单元和功能测试的Symfony2应用程序,我想知道是否有通常的做法来分离单元和功能测试,以便在运行测试套件时我没有编译配置等的开销? A unit test suite shouldn't depend on the presence of a database, or a particular configuration. 单元测试套件不应该依赖于数据库或特定配置的存在。 I was thinking of adopting a naming pattern to disambiguate functional tests, or to somehow make two different test suites, one excluding the Tests/Controller directory in a bundle, and the other only including that pattern. 我正在考虑采用命名模式来消除功能测试的歧义,或以某种方式创建两个不同的测试套件,一个不包括捆绑中的Tests / Controller目录,另一个仅包括该模式。

Is this a concern shared by anyone else, and what answers have you come to? 这是否是其他任何人共同关注的问题,您有什么答案? Does anyone else share my sense that, if possible, unit and functional tests in Symfony2 apps should ideally be segregated by default? 有没有其他人分享我的感觉,如果可能的话,Symfony2应用程序中的单元和功能测试在理想情况下应该默认隔离?

Usually people use different tools for unit and acceptance/functional tests: PHPUnit for the former and Behat for the latter. 通常人们使用不同的工具进行单元和验收/功能测试:前者为PHPUnit,后者为Behat With Behat you'll have your tests in the Features namespace and will run them with the app/console -e=test behat command, while PHPUnit with phpunit command. 使用Behat,您将在Features命名空间中进行测试,并使用app/console -e=test behat命令运行它们,而使用phpunit命令运行PHPUnit。 FOSCommentBundle is an example of this. FOSCommentBundle就是一个例子。

If you don't want to use Behat for this, I've seen some people suggesting to use the Tests namespace for unit tests and the Test namespace for functional ones. 如果您不想为此使用Behat,我会看到有些人建议使用Tests命名空间进行单元测试,使用Test命名空间进行功能Test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM