解决SimpleTest 1/2 test cases complete的问题
最近一直在用SimpleTest测试代码,发现这个问题其实已经很久了,但一直因为无关痛痒没有去解决,今天终于憋足劲把它搞定了,把过程写出来给大家分享:) 复现问题 首先新建一个test.php,内容如下: 现在执行这个测试,你会发现test cases complete的数字不
最近一直在用SimpleTest测试代码,发现这个问题其实已经很久了,但一直因为无关痛痒没有去解决,今天终于憋足劲把它搞定了,把过程写出来给大家分享:)
复现问题
首先新建一个test.php,内容如下:
现在执行这个测试,你会发现test cases complete的数字不对劲。显示的TestCase总数多于真实的TestCase数量。如下图:
排查原因
Google无果后,只能自己排查SimpleTest源码了。先在项目里搜索”test cases complete”,定位到reporter.php:
分别追踪$this->getTestCaseProgress()和$this->getTestCaseCount(),前者的数量和实际使用的TestCase数量符合,所以判定问题出在后者。
后者返回的是SimpleScorer::$size,这个属性在新建SimpleScorer实例时被初始化为null,在TestSuite::run()时通过SimpleScorer::paintGroupStart()被赋值为TestSuite::getSize():
此时将$this->cases输出,可以看到不仅有自己编写的TestCase,还有基类WebTestCase。
究其原因,这些类是通过SimpleFileLoader::createSuiteFromClasses()从文件中解析出来的,但基类WebTestCase并不包含实际的测试代码,却被计入了TestCase总数。
在TestSuite::getSize()中有个判断,如果SimpleTest::isIgnored( $case )为true,则不增加$count。但是遗憾的是SimpleTest默认的IgnoreList居然是空的,不包含自己提供的WebTestCase、UnitTestCase等基类:
解决方案
找到原因之后,解决问题就很简单了。在代码中自己用SimpleTest::ignore()将WebTestCase添加到IgnoreList即可:
再执行测试,大功告成!
原文地址:解决SimpleTest 1/2 test cases complete的问题, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Huawei is rolling out software version 5.0.0.100(C00M01) for the Watch GT 5 and the Watch GT 5 Prosmartwatchesglobally. These two smartwatches recently launched in Europe, with the standard model arriving as the company’s cheapest model. This Harmony

Katsuhiro Harada, the Tekken series director, once seriously tried to bring Colonel Sanders into the iconic fighting game. In an interview with TheGamer, Harada revealed that he pitched the idea to KFC Japan, hoping to add the fast-food legend as a g

Earlier in September 2024, Anker's Zolo 140W charger was leaked, and it was a big deal since it was the first-ever wall charger with a display from the company. Now, a new unboxing video from Xiao Li TV on YouTube gives us a first-hand look at the hi

The launch of Samsung's long-awaited 'Special Edition' foldable has taken another twist. In recent weeks, rumours about the so-called Galaxy Z Fold Special Edition went rather quiet. Instead, the focus has shifted to the Galaxy S25 series, including

Xiaomi will shortly launch the Mijia Graphene Oil Heater in China. The company recently ran a successful crowdfunding campaign for the smart home product, hosted on its Youpin platform. According to the page, the device has already started to ship to

Garmin is ending the month with a new set of stable updates for its latest high-end smartwatches. To recap, the company released System Software 11.64 to combat high battery drain across the Enduro 3, Fenix E and Fenix 8 (curr. $1,099.99 on Amazon).

Tesla is rolling out the latest Full Self-Driving (Supervised) version 12.5.5 and with it comes the promised Cybertruck FSD option at long last, ten months after the pickup went on sale with the feature included in the Foundation Series trim price. F

With a history of over one decade, Manjaro is regarded as one of the most user-friendly Linux distros suitable for both beginners and power users, being easy to install and use. Mostly developed in Austria, Germany, and France, this Arch-based distro
