Netbeans 中的 Kohana 和 PhpUnit
我使用 Kohana 3(IDE:Netbeans)编写了一些 PHP 代码,并对编写代码测试的想法感到兴奋。这听起来很酷,但我几乎没有什么并发症和担忧。
为什么在浏览器中使用 Kohana unittest 模块比在 Netbeans 或命令行中运行测试快 5 倍?
我如何排除所有 kohana 内部测试?在 PHPUnit .xml 配置文件中?
为什么当运行任何测试时,我在 Netbeans 面板中看到两个条目 - 一个带有黄色三角形(显示“文件 x 已跳过”),另一个条目包含正常测试结果。我确实在每次测试中都得到了双重条目,还有那些来自 Kohana 的本地人。我不介意,但这很奇怪。
在网络上,我看到了 PHPUnit 的示例、教程和截屏视频,其中包含示例类和方法,这些类和方法添加两个数字或显示名称或执行其他一些琐碎的事情。我已经学会了做这些断言,但是我如何在 Kohana 中测试我的代码?我的模型 90% 都是 ORM 的东西。控制器?如何?欢迎提供任何“操作方法”和示例。
我在 Ruby 教程中看到有关 Rspec 的一种通过使用测试环境数据库和完成测试后回滚来测试数据库的方法。还模拟了单击链接等用户操作。 PHPUnit 可以吗?
I do some PHP with Kohana 3 (IDE:Netbeans), and got excited about idea of writing tests for code. It sounds pretty cool thing to do, but i have few complications and worries.
Why using Kohana unittest module in browser is like 5 times faster then running tests in Netbeans or command Line ?
How could i exclude all kohana internal tests? In the PHPUnit .xml configuration file ?
Why when run any test i've got in Netbeans panel two entries for it - one with yellow triangle (it says 'file x skipped'), and entry with normal test result. I do get that double entries for every test, also those native from Kohana. I don't mind but it's strange.
All over the Web i see examples, tutorials and screencasts of PHPUnit with sample classes and methods that add two numbers or displays name or do some other trivial things. I've learnt to do those kind of assertions, but how could i test my code in Kohana? My Models are 90% ORM stuff. Controllers? How? Any 'How-tos' and examples are welcome.
I've seen in Ruby tutorial about Rspec a way to test DB by using testing enviroment Databse and rollbacks after finisning tests. Also user actions like clicking links were simulated. Is it possible with PHPUnit ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于什么必须测试、什么不需要测试一直存在很多讨论。一般来说,我的观点是,您不应该测试应该工作的东西,例如数据库驱动程序和连接,这与您的代码无关。然后有些人认为无论如何你都应该能够测试它,但在大多数环境中这并不是一件容易的事情,而且通常会很麻烦。
一般来说,应该测试控制器操作以及您编写的任何帮助程序或模块。通常,人们使用模拟框架的范例来绕过数据库。这样做的好处是测试速度大大提高。我想也有几个 PHP 模拟框架。
另一件需要记住的重要事情是您还需要进行用户测试。这无法用您在 kohana 中编写的测试类型来模拟。为此,查看 http://seleniumhq.org/ 很有趣
There always has been a lot of discussion on what has to be tested and what has not to be tested. Generally my opinion is that you shouldn't test things that should work, like the database driver and connection, this has little to do with your code. Some then argue that you should be able to test it anyway, but in most environment this isn't an easy thing to do and usually a big hassle.
Generally controller actions should be tested as well as any helpers or modules you've written. Usually one uses the paradigm of a mocking framework to get around the database. The good thing about this is a gigantic speed increase in your testing. There are several PHP mocking frameworks as well I suppose.
Another great thing to keep in mind is that you also have user testing. This cannot be simulated with the kind of tests you write in kohana. For this it is interesting to look at http://seleniumhq.org/
最好将这样一个杂乱的问题分成多个SO问题。
--exclude-group kohana
It's probably better to split such a rambling question into multiple SO questions.
--exclude-group kohana