duanchandun1860 2013-02-12 08:17
浏览 69
已采纳

PHPUnit&Behat; 补充还是替代?

I have been looking around SO and Google, but I couldn't really get a definitive answer.

PHPUnit is a framework for unittesting, like JUnit. I use it, also in combination with the Selenium-extension for functional testing. When browsing around I see Behat/Mink keeps on getting mentioned. But I do not completely understand how Behat fits in here.

With Behat you write scenarios in human-readable format. Behat can then translate that into skeleton classes for a new project? But does it also provide skeleton classes for unittesting? Do you write unittests using Behat, or you would use PHPUnit / SimpleTest for those?

But then Behat/Mink does replace PHPUnit_Selenium-extension for functional testing?

Do you use Behat only for new projects, or can it also be adapted to existing projects?

  • 写回答

3条回答 默认 最新

  • douwudie8060 2013-02-12 11:20
    关注

    Yes, I would consider Behat to be an alternative to phpUnit, both for general code testing and for functional testing using browser automation.

    For general testing, phpUnit is a more well-established product, while Behat is focussed on tests written using "BDD" methodology (Behaviour Driven Design). phpUnit does also have BDD features, but Behat is much more targetted toward that style.

    Since we're talking about functional browser tests rather than unit tests, you probably aren't thinking about some of the more powerful unit testing features that they have; you just want to write the browser automation. For this, you really can pick whichever of the two suits you the best.

    There are subtle edge-cases where each of them has strengths over the other, but for most cases they're both capable of running test scripts across a variety of browsers.

    My preference would go to Behat/Mink, on the grounds that it is more flexible; it can support several browser automation engines, including Selenium and Sahi, which means that if you hit an issue with one, you can switch your tests to the other and carry on. We had this exact situation, trying to get some Mink test scripts to work in Selenium; switching to Sahi made it work, and involved changing just a single line of test code.

    It's also worth adding that Mink can be used on its own without Behat, if you don't want to write BDD style tests.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab