测试Laravel 4应用程序的第一枪(PHPSpec/BDD与PHPUnit/TDD) [英] First Shot at Testing Laravel 4 apps (PHPSpec/BDD vs. PHPUnit/TDD)

查看:130
本文介绍了测试Laravel 4应用程序的第一枪(PHPSpec/BDD与PHPUnit/TDD)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为这个问题努力太久了.我知道我只需要跳进其中一个,因为它们显然都是可行/有用的工具,但是已经被围困了,研究了两个星期.

I have been wrestling with this question for far too long now. I know I need to just jump into one or the other since they are both obviously viable/useful tools, but have been stuck on the fence, researching both, for weeks.

PHPUnit PHPSpec -哪一个可能会导致更好的长期可维护性和编程实践?

PHPUnit vs. PHPSpec - Which one may lead to better long-term maintainability and programming practices?

我已经与几位经验丰富的PHPUnit进行过交谈-> PHPspec转换/用户现在对PHPspec宣誓就职,他们声称由于使用BDD方法,PHPspec可以促进更好的设计.但是,由于它是一个更新得多的工具,因此与PHPUnit相比缺少社区/教程.

I have talked to several seasoned PHPUnit -> PHPspec converts/users who now swear by PHPspec, claiming that it promotes better design thanks to its BDD approach. However, since it is a much newer tool there is a lack of community/tutorials in comparison with PHPUnit.

当前,我的PHP开发专注于Laravel 4开发.

Currently, my PHP development is focused around Laravel 4 development.

在基本上将PHPUnit引入Laravel框架的地方,似乎这可能是更容易的选择,但是我真的很喜欢PHPSpec的BDD方面.但是,似乎PHPSpec不想与Laravel的外观设置很好地配合使用(我还发现,在可能的情况下避免这种情况可能是个好习惯).

Where PHPUnit is basically baked into the Laravel framework, it seems like that may be the easier choice up front, but I really like the BDD aspect of PHPSpec. However, it seems that PHPSpec doesn't want to play nicely with Laravel's facade setup (which I'm also finding may be a good practice to steer clear of when possible).

我真正的难题是,其中哪一个更可能成功地集成到现有的Laravel 4项目中,而现有的测试覆盖率为零.

My real conundrum is which of these will be more likely to be successfully integrated into an existing Laravel 4 project with zero existing test coverage.

在将PHPUnit和PHPSpec都集成到现有项目中的过程中,我有一个早期/简短的技巧,但是实际上只是不确定从哪里开始编写初始测试,最后暂时取消了它们.

I had an early/brief stab at integrating both PHPUnit and PHPSpec into an existing project, but really just wasn't sure where to begin with writing the initial tests and ended up scrapping them for the time being.

从长远来看,我真的是在尝试找出哪些可能更值得投资.

I am really trying to sort out which one may be more worth investing some time into in the long run.

任何经历过这两次的人所提供的任何资源/见识,都将不胜感激.

Any resources/insight from anyone who has experienced both would be greatly appreciated.

推荐答案

PhpSpec

PhpSpec是一个设计工具.如果您不习惯TDD(测试优先方法),那么一开始就会使您的生活变得艰难.

PhpSpec is a design tool. It will make your life hard in the beginning if you're not used to TDD (test-first approach).

在此过程中,您将学到很多东西.您也会发誓. PhpSpec无法完成许多被认为是不良做法的事情(例如,部分模拟).您必须了解它并接受它.测试Laravel的外观很难,因为那不是OOP.

You'll learn a lot during the process though. You will also swear a lot. Many things, which are considered a bad practice, are not possible with PhpSpec (like partial mocks for example). You'll have to understand it and embrace it. Testing Laravel's facade's is hard, 'cause that's not OOP.

使用PhpSpec来测试现有代码要困难得多,因为您必须首先使其可测试(使用测试优先方法更容易).

It's much harder to test an existing code with PhpSpec, since you have to make it testable first (which is easier with a test-first approach).

PhpUnit

另一方面,PhpUnit是测试工具.您可以将其与TDD,BDD或任何您使用的名称一起使用.但是您不必.

On the other hand, PhpUnit is a testing tool. You can use it with TDD, BDD or whatever you call it. But you don't have to.

选择

如果您的目标是学习如何更好地设计,并且您致力于测试优先方法,那么PhpSpec将为您提供帮助.如果您要测试或验证,PhpUnit是您的朋友.

If your aim is to learn how to design better and you're commited to test-first approach, PhpSpec will help you. If your aim is to test or verify, PhpUnit is your friend.

TDD与BDD

它不是 TDD BDD .至少从代码级别的角度来看,它们是相同的. BDD开始于对TDD的重新定义,提供了更好的术语.现在,它超出了代码级别,并且不仅限于此.如今,我更喜欢使用Gojko Adzic提出的术语-示例规范.

It's not either TDD or BDD. At least from a code level perspective, they're the same. BDD started as a TDD-redefined, offering a better terminology. Now it goes beyond the code level and it's so much more than that. These days I prefer to use a term proposed by Gojko Adzic - Specification by Example.

这篇关于测试Laravel 4应用程序的第一枪(PHPSpec/BDD与PHPUnit/TDD)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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