testhelper类的正确位置是什么? (phpunit/最佳实践) [英] Whats the right place for testhelper-classes? (phpunit/best practise)

查看:154
本文介绍了testhelper类的正确位置是什么? (phpunit/最佳实践)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用PHPUnit测试我的应用程序.因此,像往常一样,我有我的应用程序类和带有测试类的第二棵树.现在,我需要对一种虚拟/模拟对象进行测试,并且想知道应该将它们放置在何处.它是一个不同的用例,应该放置在公共lib文件夹中还是首选?

I want to test my application with PHPUnit. So I have my application-classes and a second tree with test-classes as usual. Now I need for some test a kind of Dummy/Mock-Objects and I want to know where I should place them. Is it a different usecase and it should be place in common lib folder or what is to prefer?

推荐答案

我喜欢镜像正在处理的项目的文件结构.

I like to mirror the file structure of the project I am working on.

/project
  app/
  app/models/BankAccount.php
  tests/
    suite/
      app
      app/models/BankAcountTest.php
    mocks
      app/
      app/models/BankAccountMock.php

我发现通过这种方式可以使一切保持井井有条.如果我不打算重用它们,则将它们放在测试用例文件中.正如其他评论所述,大多数Mocks可以由PHPUnit生成,但有时仅滚动自己即可.

I find doing it this way keeps everything organized. I will put small Mocks or stubs in the Test Case File if I don't intend to reuse them. As was stated in the other comments, most Mocks can be generated by PHPUnit, but sometimes it is easier just to roll your own.

这篇关于testhelper类的正确位置是什么? (phpunit/最佳实践)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆