php SimpleTest 与 PHPunit
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SimpleTest vs PHPunit
提问by paan
I was wondering if anyone that has experience in both this stuff can shed some light on the significantdifference between the two if any?
我想知道是否有人在这两个方面都有经验,如果有的话,是否可以阐明两者之间的显着差异?
Any specific strength of each that makes it suitable for any specific case?
每个的任何特定强度使其适用于任何特定情况?
采纳答案by edorian
This question is quite dated but as it is still getting traffic and answers I though I state my point here again even so I already did it on some other (newer) questions.
这个问题已经过时了,但由于它仍在获得流量和答案,我虽然在这里再次说明了我的观点,但我已经在其他一些(较新的)问题上做了它。
I'm really reallybaffled that SimpleTest stillis considered an alternative to phpunit. Maybe i'm just misinformed but as far as I've seen:
我真的很困惑 SimpleTest仍然被认为是 phpunit 的替代品。也许我只是被误导了,但据我所知:
- PHPUnit is the standard; most frameworks use it (like Zend Framework (1&2), Cake, Agavi, even Symfony is dropping their own Framework in Symfony 2 for phpunit).
- PHPUnit is integrated in every PHP IDE (Eclipse, Netbeans, Zend Stuide, PHPStorm) and works nicely.
- Simpletest has an eclipse extension for PHP 5.1 (a.k.a. old) and nothing else.
- PHPUnit works fine with every continuous integration server since it outputs all standard log files for code coverage and test reports.
- Simpletest does not. While this is not a big problem to start with it will bite you big time once you stop "just testing" and start developing software (Yes that statement is provocative :) Don't take it too seriously).
- PHPUnit is actively maintained, stable and works great for every codebase, every scenario and every way you want to write your tests.
- (Subjective) PHPUnit provides much nicercode coverage reports than Simpletest
- With PHPUnit you also get these reports inside your IDE (Netbeans, Eclipse, ...)
- Also there are a couple of suggestings for a
web interface to phpunit tests.
- PHPUnit 是标准;大多数框架都使用它(例如 Zend Framework (1&2)、Cake、Agavi,甚至 Symfony 也在 Symfony 2 for phpunit 中删除了他们自己的框架)。
- PHPUnit 集成在每个 PHP IDE(Eclipse、Netbeans、Zend Stuide、PHPStorm)中并且运行良好。
- Simpletest 有一个针对 PHP 5.1(又名旧)的 eclipse 扩展,没有别的。
- PHPUnit 可以很好地与每个持续集成服务器配合使用,因为它输出代码覆盖率和测试报告的所有标准日志文件。
- Simpletest 没有。虽然从一开始这不是什么大问题,但一旦您停止“只是测试”并开始开发软件,它就会让您大吃一惊(是的,该声明具有挑衅性 :) 不要太当真)。
- PHPUnit 得到积极维护、稳定且适用于每个代码库、每个场景以及您想要编写测试的每种方式。
- (主观)PHPUnit 提供了比 Simpletest更好的代码覆盖率报告
- 使用 PHPUnit,您还可以在 IDE 中获取这些报告(Netbeans、Eclipse 等)
- 还有一些关于
web interface to phpunit tests.
I've yet to see any argument in favor of SimpleTest. It's not even simpler to install since PHPUnit is available via pear:
我还没有看到任何支持 SimpleTest 的论据。由于 PHPUnit 可通过 pear 获得,因此安装起来并不简单:
pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit
and the "first test" looks pretty much the same.
和“第一次测试”看起来几乎一样。
As of PHPUnit 3.7it's even easier to installit by just using the PHAR Archive
因为只需使用PHPUnit 3.7它就可以更轻松地安装它PHAR Archive
wget http://pear.phpunit.de/get/phpunit.phar
chmod +x phpunit-3.7.6.phar
or for windows just downloadingthe phar and running:
或者对于 Windows 只需下载phar 并运行:
php phpunit-.phar
or when using the supported composer installways like
或者当使用支持的 composer 安装方式时
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
to your composer.json.
到您的 composer.json。
For everything you want to test PHPUnit will have a solution and you will be able to find help pretty much anywhere (SO, #phpunit irc channel on freenode, pretty much every php developer ;) )
对于您想要测试的所有内容,PHPUnit 都有一个解决方案,您几乎可以在任何地方找到帮助(所以,freenode 上的 #phpunit irc 频道,几乎每个 php 开发人员;))
Please correct me if I've stated something wrong or forgot something :)
如果我说错了什么或忘记了什么,请纠正我:)
Overview of PHP Testing tools
PHP 测试工具概述
Video: http://conference.phpnw.org.uk/phpnw11/schedule/sebastian-bergmann/
视频:http: //conference.phpnw.org.uk/phpnw11/schedule/sebastian-bergmann/
Slides: http://www.slideshare.net/sebastian_bergmann/the-php-testers-toolbox-osi-days-2011
幻灯片:http: //www.slideshare.net/sebastian_bergmann/the-php-testers-toolbox-osi-days-2011
It mentions stuff like Atoumwhich calls its self: "A simple, modern and intuitive unit testing framework for PHP!"
它提到了像Atoum这样自称的东西:“一个简单、现代和直观的 PHP 单元测试框架!”
Full disclosure
全面披露
I've originally written this answer Jan. 2011 where I had no affiliation with any PHP Testing project. Since then I became a contributor to PHPUnit.
我最初在 2011 年 1 月写了这个答案,当时我与任何 PHP 测试项目都没有关系。从那时起,我成为了 PHPUnit 的贡献者。
回答by Eric Scrivner
I prefer PHPUnit now, but when I started out I used SimpleTest as I didn't always have access to the command line. SimpleTest is nice, but the only thing it really has over PHPUnit, in my opinion, is the web runner.
我现在更喜欢 PHPUnit,但是当我开始时我使用 SimpleTest,因为我并不总是可以访问命令行。SimpleTest 很好,但在我看来,它唯一真正超过 PHPUnit 的是 web runner。
The reasons I like PHPUnit are that it integrates with other PHP developer tools such as phing(as does SimpleTest), phpUnderControl, and Xinc. As of version 3.0 it has mockingsupport, is being actively developed, and the documentation is excellent.
我喜欢 PHPUnit 的原因是它与其他 PHP 开发人员工具集成,例如phing(就像 SimpleTest)、phpUnderControl和Xinc。从 3.0 版开始,它具有模拟支持,正在积极开发中,并且文档非常好。
Really the only way to answer this question for yourself is to try both out for a time, and see which fits your style better.
真正为自己回答这个问题的唯一方法是尝试一段时间,看看哪个更适合你的风格。
EDIT: Phing now integrates with SimpleTest as well.
编辑:Phing 现在也与 SimpleTest 集成。
回答by stfan
- I could NOT understand how to download and install PHPUnit.
I could, however, easily understand how to install SimpleTest.
(As far as i can remember the instructions for PHPUnitsaid something along the lines of "install it via PEAR and we won't give any instructions on how to do it any other way") see:
- http://www.phpunit.de/manual/current/en/installation.html
- 我不明白如何下载和安装 PHPUnit。
但是,我可以轻松理解如何安装 SimpleTest。
(据我所知,PHPUnit的说明中说了一些类似“通过 PEAR 安装它,我们不会以任何其他方式进行安装”的说明)请参阅:
- http://www.phpunit.de/manual/current/en/installation.html
For SimpleTest, just download it and point to it from your code.
对于SimpleTest,只需下载它并从您的代码中指向它。
So Simpletest won for me.
所以 Simpletest 为我赢了。
回答by neu242
Baphled has a nice article on SimpleTest vs PHPUnit3.
Baphled 有一篇关于SimpleTest 与 PHPUnit3的好文章。
回答by Jens A. Koch
Half of the mentioned points in the accepted answer are simply not true:
接受的答案中提到的一半要点根本不正确:
SimpleTesthas
- the easier setup (extract to folder, include and run)
- simply check the folder into version control (try to do that with phpunit nowadays :))
- less dependencies and lots of extensions (webtester, formtester, auth)
- a good code coverage reporter, which is easy to extend (dots, function names, colors)
- a code coverage summary (finally landed in PHPUnit 4.x)
- a decent web runner and an ajax web runner, with groups and single file executions
- still better diff tool (with no whitespace or newline problems)
- an adapter/wrapper to run SimpleTests by phpUnit and vice versa
- compatibility PHP5.4+
- 更简单的设置(解压到文件夹,包含并运行)
- 只需将文件夹检查到版本控制中(现在尝试使用 phpunit 执行此操作:))
- 更少的依赖和大量的扩展(webtester、formtester、auth)
- 一个很好的代码覆盖报告器,易于扩展(点、函数名称、颜色)
- 一个代码覆盖率总结(终于登陆PHPUnit 4.x)
- 一个体面的网络运行器和一个 ajax 网络运行器,具有组和单个文件执行
- 更好的差异工具(没有空格或换行符问题)
- 通过 phpUnit 运行 SimpleTests 的适配器/包装器,反之亦然
- 兼容性 PHP5.4+
The downside:
不足之处:
- not industry standard (PHPUnit)
- not actively maintained
- 非行业标准 (PHPUnit)
- 没有积极维护
回答by Jens A. Koch
Well I made a phpUnit web based UI test case runner and made it available on sourceforge. Uses ajax and has quite cool interface as well if you want to give it a shot check it at sourceforge. The project name is phpunitwebui and the website is http://phpunitwebui.sourceforge.net/
好吧,我制作了一个基于 phpUnit Web 的 UI 测试用例运行器,并在 sourceforge 上提供了它。使用 ajax 并具有非常酷的界面,如果您想尝试一下,请在 sourceforge 上检查一下。项目名称为phpunitwebui,网址为http://phpunitwebui.sourceforge.net/
回答by Erik ?jebo
I found SimpleTest was even easier than PHPUnit to set up. Just extract it and you are good to go. A benefit of this is if you are working at more than one machine, since you can store the whole testing framework the same way as your source code, and thereby know that you are using the same framework code. Especially if you modify it in any way.
我发现 SimpleTest 比 PHPUnit 更容易设置。只需提取它,你就可以开始了。这样做的好处是,如果您在多台机器上工作,因为您可以以与源代码相同的方式存储整个测试框架,从而知道您正在使用相同的框架代码。特别是如果你以任何方式修改它。
So, I would say that a strength of SimpleTest is that it is very light weight and portable.
所以,我想说 SimpleTest 的一个优点是它非常轻巧且便于携带。
SimpleTest also ships with a very simple HTML GUI, which is quite easy to extend if you want to. As far as I know, PHPUnit does not include a HTML GUI, but there are GUI:s available to download, such as Cool.
SimpleTest 还附带一个非常简单的 HTML GUI,如果您愿意,它很容易扩展。据我所知,PHPUnit 不包括 HTML GUI,但有 GUI:s 可供下载,例如Cool。
回答by T0xicCode
As it has been pointed, it's mostly a preference choice, as both will run the tests you write for it and report back the results.
正如所指出的,这主要是一种偏好选择,因为两者都将运行您为其编写的测试并报告结果。
The Simpletest web UI is very useful, but it can also sometimes get cumbersome. In my current project, I would have had to put more work into a system to make my application (an API) work with the web interface (set up apache correctly, copy files to the public_html root, etc.) than it would have been to simply run phpunit from the eclipse workspace. Therefore I choose PHPUnit. Also, the use of PEAR was a big plus since you don't need to manually track updates. Simply run pear upgradeonce in a while and PHPUnit will be kept up-to-date.
Simpletest Web UI 非常有用,但有时也会变得很麻烦。在我当前的项目中,我将不得不在系统中投入更多的工作,以使我的应用程序(API)与 Web 界面一起工作(正确设置 apache,将文件复制到 public_html 根目录等)。只需从 eclipse 工作区运行 phpunit。因此我选择PHPUnit。此外,使用 PEAR 是一大优势,因为您无需手动跟踪更新。只需pear upgrade偶尔运行一次,PHPUnit 就会保持最新。
回答by tru7
This is from the point of view of a very casual PHP developer:
这是从一个非常随意的 PHP 开发人员的角度来看的:
It took me two days to grasp PHPUnit, mostly trying to debug under Eclipse that I finally gave up.
花了两天时间掌握PHPUnit,主要是尝试在Eclipse下调试最终放弃。
It took me two hours to setup Simpletest including debug under Eclipse.
我花了两个小时来设置 Simpletest,包括在 Eclipse 下进行调试。
Maybe I will find the shortfalls of Simpletest in the future but so far it does well what I need: TestClasses, Mock objects, test-code debugging, and web interface for a quick snapshot of the situation.
也许我会在未来找到 Simpletest 的不足,但到目前为止它很好地满足了我的需求:TestClasses、Mock 对象、测试代码调试和用于快速了解情况的 Web 界面。
Again: This from the point of view of a very casual PHP user(not even developer :-)
再次:这是从一个非常随意的 PHP 用户的角度来看的(甚至不是开发人员 :-)
回答by mr1031011
This question is old, but I want to add my experience: PHPUnit seems to be the standard now, but if you work with a legacy system that uses lots and lots of global variables, you may get stuck from the get go. It seems like there is no good way to do tests with global vars in PHPUnit, you seem to have to set your variables via $GLOBALS which is NO GOOD if you have tons of files setting global variables everywhere. OK some may say that the problem is in the legacy system but that doesn't mean we cannot do tests on such system. With SimpleTest such thing is simple. I suppose if PHPUnit allows us to include a file globally, not within any class/function scope then it wouldn't be too much of an issue as well.
这个问题很老了,但我想补充一下我的经验:PHPUnit 现在似乎是标准,但是如果您使用使用大量全局变量的遗留系统,您可能会从一开始就陷入困境。似乎没有什么好方法可以在 PHPUnit 中使用全局变量进行测试,您似乎必须通过 $GLOBALS 设置变量,如果您有大量文件在各处设置全局变量,这将是不好的。好吧,有些人可能会说问题出在遗留系统上,但这并不意味着我们不能在这样的系统上进行测试。使用 SimpleTest 这样的事情很简单。我想如果 PHPUnit 允许我们在全局范围内包含一个文件,而不是在任何类/函数范围内,那么它也不会成为太大的问题。
Another promising solution is http://www.enhance-php.com, looks nice :)
另一个有前途的解决方案是http://www.enhance-php.com,看起来不错:)

