Netbeans 中的 Kohana 和 PhpUnit

发布于 2024-11-28 14:50:10 字数 627 浏览 2 评论 0原文

我使用 Kohana 3(IDE:Netbeans)编写了一些 PHP 代码,并对编写代码测试的想法感到兴奋。这听起来很酷,但我几乎没有什么并发症和担忧。

  1. 为什么在浏览器中使用 Kohana unittest 模块比在 Netbeans 或命令行中运行测试快 5 倍?

  2. 我如何排除所有 kohana 内部测试?在 PHPUnit .xml 配置文件中?

  3. 为什么当运行任何测试时,我在 Netbeans 面板中看到两个条目 - 一个带有黄色三角形(显示“文件 x 已跳过”),另一个条目包含正常测试结果。我确实在每次测试中都得到了双重条目,还有那些来自 Kohana 的本地人。我不介意,但这很奇怪。

  4. 在网络上,我看到了 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.

  1. Why using Kohana unittest module in browser is like 5 times faster then running tests in Netbeans or command Line ?

  2. How could i exclude all kohana internal tests? In the PHPUnit .xml configuration file ?

  3. 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.

  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久随 2024-12-05 14:50:10

关于什么必须测试、什么不需要测试一直存在很多讨论。一般来说,我的观点是,您不应该测试应该工作的东西,例如数据库驱动程序和连接,这与您的代码无关。然后有些人认为无论如何你都应该能够测试它,但在大多数环境中这并不是一件容易的事情,而且通常会很麻烦。

一般来说,应该测试控制器操作以及您编写的任何帮助程序或模块。通常,人们使用模拟框架的范例来绕过数据库。这样做的好处是测试速度大大提高。我想也有几个 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/

开始看清了 2024-12-05 14:50:10

最好将这样一个杂乱的问题分成多个SO问题。

  1. 不知道。与 apache 将请求传递给 PHP 相比,NetBeans 调用 phpunit 可能会产生调用开销。
  2. 这可能是可能的,或者您可以找到一种方法来设置以下选项: --exclude-group kohana
  3. 不知道抱歉。
  4. AFAIK PHPUnit 无法进行客户端交互测试。如何进行系统行为测试本身就是一个问题。

It's probably better to split such a rambling question into multiple SO questions.

  1. No idea. Perhaps there's an invocation overhead for NetBeans to invoke phpunit, compared to apache passing the request to PHP.
  2. That might be possible, or you could find a way to set the following option: --exclude-group kohana
  3. No idea sorry.
  4. AFAIK PHPUnit can't do client-interaction tests. How to do system behaviour testing could be a question on its own.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文