我的 php 项目中的单元测试文件应该存储在哪里?
我在 subversion 中有一个 php 项目,具有典型的 /project/trunk/
、/project/test/
、/project/branches/
结构。我想开始使用 PHPUnit 编写一些单元测试。在版本控制中存储这些文件的好地方在哪里?
如果我把它们放在 /project/unittests/
中,我就必须并行检查它们测试的目录,所以这有点麻烦,我必须确保我做得正确。如果我将它们保留在项目中,例如在 /project/trunk/unittests/
中,那么当我部署站点时它们就会在那里,除非我有一些额外的钩子不导出它们,或者至少确保我的 .htaccess 不允许为它们提供服务。
I have a php project in subversion, with the typical /project/trunk/
, /project/test/
, /project/branches/
structure. I want to start writing some unit tests with PHPUnit. Where is a good place to store these files in version control?
If I put them in /project/unittests/
, I would have to check out the directory they test in parallel, so that's a little hassle that I have to make sure I do properly. If I keep them in the project, say at /project/trunk/unittests/
, then they will be there when I deploy the site, unless I have some extra hooks not to export them, or at least make sure my .htaccess doesn't allow serving them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我确实将它们存储在我的项目目录中,而不是单独的 svn 目录中,因为单元测试与项目状态直接相关,并且可能因状态而异。您应该注意它们不可通过网络访问。
例如,对于每个状态,我的结构如下所示(使用 zend 框架),web 是唯一可通过 Web 访问的目录:
I do store them in my project directory and not in a seperate svn directory as unittests are directly related to the project state and may differ from state to state. You should just take care that they are not web-accessible.
For example for each state my structure looks like this (using the zend framework), web is the only web-accessible directory:
您可以将它们放在任何地方。就我个人而言,我总是这样设置我的项目:
当我将主干合并到开发分支时,我不提交“trunk/tests”目录。
这样,使用开发分支创建的任何标签都不包含测试。
You can put them anywhere. Personally I always setup my project like this:
When I merge the trunk to the development branch, I don't commit the "trunk/tests" directory.
That way, any tag created using the development branch do not include the tests.
我会将单元测试与其余代码放在一起。当然在一个单独的文件夹中,但它应该位于您正在处理的分支中。我认为将它们部署到生产中没有问题。您可能希望在生产环境中运行测试,以确保一切都适用于生产 php 版本。
I would put the unit tests with the rest of your code. Certainly in a separate folder, but it should be with the branch you are working on. I don't see a problem with deploying them to production. You'll probably want to run the tests in production to make sure everything is working with the production php version.