向现有 Yii 项目添加测试
我已经用 Yii 完成了一个正在运行的项目。对于下一个开发阶段,我想使用 TDD 方法。现在,我一直在尝试安装所有复杂的东西(PHP 和 Selenium RC,令人头疼!),最后开始工作。当我创建 SampleTest.php 并从控制台 phpunit SampleTest.php 运行它时,它工作得很好。
现在的问题是,这个示例测试实际上是一个示例,它没有使用我的项目中定义的任何模型。我想创建模型的新实例,填充它们等。但是如果不一一包含所有模型、控制器等,我该如何做到这一点呢?
我手里有《Yii 权威指南》,在测试环境设置下,它说如果我使用 yiic webapp 创建新应用程序,那么将创建一个完整的文件和目录列表(这里是本书该部分的链接)。如果是我的情况怎么办?我已经生成了应用程序?我有点迷失了,非常感谢任何帮助。
谢谢!
I have an already running project done with Yii. For the next development phase, i'd like to use a TDD methodolody. Now, I have been playing around a bit getting all the complicated stuff installed (PHP and Selenium RC, headaches!), and finally gottem up and working. When I create a SampleTest.php and run it from console phpunit SampleTest.php it works just fine.
Now the issue is that this sample test is in fact an example, it doesn't use any of the models defined in my project. I would like to create new instances of my models, populate them, etc. But how can I do that without including one by one all the models, controllers, etc?
I have in my hands "The definitive guide to Yii" which, under Test Environment Setup, it says that if i use yiic webapp to create the new app, then a whole list of files and directories will be created (here is a link to that part of the book). What if its my case? I already have the application generated? I'm kinda lost, any help is appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在 your_application/protected/tests/ 文件夹中创建测试:
- 单元/文件夹中的单元测试
- 位于功能/文件夹的功能测试
首先尝试通过本手册创建单元测试 - http ://www.yiiframework.com/doc/guide/1.1/en/test.unit。这很容易。
您的所有模型、组件等都将由引导脚本自动包含。
您可以在这里阅读更多相关信息(查看第 3 部分) - http:// /www.yiiframework.com/doc/guide/1.1/en/test.overview
Just create your tests at your_application/protected/tests/ folder:
- unit tests at unit/ folder
- functional tests at functional/ folder
First try create unit tests by this manual - http://www.yiiframework.com/doc/guide/1.1/en/test.unit. It's quite easy.
All your models, components, etc will be included automatically by bootstrap script.
You can read more about it here (look at Part 3) - http://www.yiiframework.com/doc/guide/1.1/en/test.overview