php PHPUnit 测试的“Web 界面”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2424457/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:24:50  来源:igfitidea点击:

"Web interface" to PHPUnit tests?

phpunit-testingtddphpunit

提问by Pekka

Is there a simple "Web interface" to running PHPUnit test suites? i.e. a PHP script that runs the test on the command line, and outputs a nicely formatted HTML result.

是否有一个简单的“Web 界面”来运行 PHPUnit 测试套件?即在命令行上运行测试的 PHP 脚本,并输出格式良好的 HTML 结果。

I develop web applications, and the day-to-day workflow usually switches between the IDE and the browser. I would like to have the unit testing in the same environment.

我开发 Web 应用程序,日常工作流程通常在 IDE 和浏览器之间切换。我想在相同的环境中进行单元测试。

I'm looking for something really simple and PHP based - I am planning to get into phpUnderControl (which has the functionality I'm looking for) but not yet.

我正在寻找一些非常简单且基于 PHP 的东西 - 我打算进入 phpUnderControl(它具有我正在寻找的功能),但还没有。

采纳答案by Gordon

You can use phing to run a PHPUnitTaskand then convert the output with:

您可以使用 phing 运行PHPUnitTask,然后使用以下命令转换输出:

  • PHPUnitReport- This task transforms PHPUnit xml reports to HTML using XSLT.
  • PHPUnitReport- 此任务使用 XSLT 将 PHPUnit xml 报告转换为 HTML。

Example:

例子:

<phpunitreport infile="reports/testsuites.xml" 
    format="frames" 
    todir="reports/tests" 
    styledir="/home/phing/etc"/>

See phpunit --helpfor the various output formats.

有关phpunit --help各种输出格式的信息,请参阅。

The 2.3 version of PHPUnit had a chapter on this, but it is gone for some time now. You might be able to find an old copy with Google somewhere.

PHPUnit 的 2.3 版本有一章关于这个,但它已经消失了一段时间。您也许可以在某处通过 Google 找到旧副本。

Since you mention this is for phpUnderControl: if you are not fixed on that, consider using Jenkins and http://jenkins-php.org.

由于您提到这是针对 phpUnderControl:如果您没有解决这个问题,请考虑使用 Jenkins 和http://jenkins-php.org

On a side note: unless we are talking CI servers, most people I know don't use PHPUnit through a web interface. They either just use the command line or their IDE integration.

附带说明:除非我们谈论 CI 服务器,否则我认识的大多数人不会通过 Web 界面使用 PHPUnit。他们要么只使用命令行,要么只使用 IDE 集成。

回答by edorian

I recently discovered Visual PHPUnitwhich looks like a very very nice interface for everyone that doesn't want to run PHPUnit from the command line:

我最近发现Visual PHPUnit对于不想从命令行运行 PHPUnit 的每个人来说,这看起来是一个非常好的界面:

Visual PHPUnit

可视化PHP单元

It seems to be the next iteration of @Matt's PHPUnit Test Report

这似乎是@Matt 的下一次迭代 PHPUnit Test Report

回答by Matt

I feel your frustration - I'm a UI guy myself. Looking at the terminal too long makes my head spin. I wrote a quick little application that you might find helpful.

我感到你的沮丧 - 我自己就是一个 UI 人。看着终端太久让我头晕目眩。我写了一个快速的小应用程序,你可能会觉得有用。

PHPUnit test application
(source: mattmueller.me)

PHPUnit test application
(来源:mattmueller.me

You can find it here: http://mattmueller.me/blog/introducing-phpunit-test-report

你可以在这里找到它:http: //mattmueller.me/blog/introducing-phpunit-test-report

Cheers! Matt

干杯! 马特

回答by Motin

After several hours of researching recently, the best PHPUnit web frontend I have come across was https://github.com/NSinopoli/VisualPHPUnit

最近经过几个小时的研究,我遇到的最好的 PHPUnit Web 前端是https://github.com/NSinopoli/VisualPHPUnit

回答by Tom

You can use Jenkinsto run any kind of tasks including PHPUnit tests. It can automatically checkout your app, run the tests, build a HTML report and even email you if the build fails.

您可以使用Jenkins运行任何类型的任务,包括 PHPUnit 测试。它可以自动检查您的应用程序、运行测试、构建 HTML 报告,甚至在构建失败时向您发送电子邮件。

Here's the templatesyou need to setup Jenkins to build a bunch of interesting reports and stats from your project.

这是您设置 Jenkins 以从您的项目构建一堆有趣的报告和统计数据所需的模板

回答by AbiusX

jframework also has a nice UI for PHPUnit. It breaks the results, and shows test coverage on all files and each file separately. It works on both web and cli, with the cli one having the benefit of dumping every test after its done (the web-based one has to wait until everything is over).

jframework 也有一个很好的 PHPUnit 用户界面。它打破了结果,并分别显示了所有文件和每个文件的测试覆盖率。它适用于 web 和 cli,cli 的好处是在完成后转储每个测试(基于 web 的测试必须等到一切都结束)。

General web output, with code coverage per file

General web output, with code coverage per file

Code coverage report for a single file

Code coverage report for a single file

回答by Pascal MARTIN

I've never seen such a web-interface... But, as you say you are always using your IDE and your webbrowser, why not think the other way ?

我从未见过这样的网络界面……但是,正如您所说,您一直在使用 IDE 和网络浏览器,为什么不换一种方式思考呢?

i.e. a possible solution would be to launch the unittests from your IDE ;-)
Which means you should be able to click on the failing tests to "jump" to either the test method, or the reason that caused the test to fail, for instance.

即一个可能的解决方案是从您的 IDE 启动单元测试 ;-)
这意味着您应该能够单击失败的测试以“跳转”到测试方法或导致测试失败的原因,例如.


In the PHP + PHPUnit world, I know that Zend Studiodoes that -- yes, it's not free, unfortunatly ;-(


在 PHP + PHPUnit 世界中,我知道Zend Studio是这样做的——是的,它不是免费的,不幸的是 ;-(


Using Eclipse PDT, a solution would be to register PHPUnit as an external tool (see or instance this blogpost : Using PHPUnit with Eclipse PDT) -- but it's quite not sexy, and you cannot click on the results to jump the the methods/tests...


使用 Eclipse PDT,一个解决方案是将 PHPUnit 注册为外部工具(请参阅或实例此博客文章:将 PHPUnit 与 Eclipse PDT 一起使用)——但它并不性感,并且您无法单击结果来跳转方法/测试...

Another solution would be to develop a plugin to integrate PHPUnit into Eclipse PDT (like it's been done for Zend Studio, I suppose)-- A phpunit4eclipsewas created some time ago, but it's just a start, and didn't get much succes, so the author didn't work on it after releasing that...

另一种解决方案是开发一个插件来将 PHPUnit 集成到 Eclipse PDT 中(我想它就像为 Zend Studio 所做的那样)——前一段时间创建了一个phpunit4eclipse,但这只是一个开始,并没有取得太大的成功,所以作者在发布后没有工作......

回答by Pekka

I found this:

我发现了这个

I stumbeld upon a post from Parth Patil, whose solution was to create an xml-report from PHPUnit and then use this xml to create your own report.

I used his solution, made it PHPUnit 3.4 compatible and also added some Reflection to see my testcase doc-comments in the report. (Note: For the refelection i use the Zend_Framework reflection class)

我偶然发现了 Parth Patil 的一篇文章,他的解决方案是从 PHPUnit 创建一个 xml-report,然后使用这个 xml 来创建您自己的报告。

我使用了他的解决方案,使其与 PHPUnit 3.4 兼容,并添加了一些反射以查看报告中的测试用例文档注释。(注意:对于重新选举,我使用 Zend_Framework 反射类)

回答by Matthieu Napoli

Ok you said you'd prefer an independent IDE solution, but just so you know there is a recent plugin that enables executing PHPUnit simply into Eclipse, and having a nice representation (like in Zend Studio, but for free).

好的,您说过您更喜欢独立的 IDE 解决方案,但只是为了让您知道最近有一个插件可以在 Eclipse 中简单地执行 PHPUnit,并且具有很好的表示(就像在 Zend Studio 中一样,但免费)。

Here is the link, the main developper replies fast to emails too if you have a problem :

这是链接,如果您有问题,主要开发人员也会快速回复电子邮件:

http://www.phpsrc.org/wiki/

http://www.phpsrc.org/wiki/

I personnaly tested some web interface, but I have always been deceived (not really practital and stable). But this is your choice.

我亲自测试了一些网络界面,但我一直被欺骗(不是很实用和稳定)。但这是你的选择。

回答by Softy

You can always use the Maven for PHP from which you can use the surefire reports (mvn site). More info here: http://www.php-maven.org

您始终可以使用 Maven for PHP,从中可以使用surefire 报告(mvn 站点)。更多信息在这里:http: //www.php-maven.org