You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
什么是 Pest?
Pest 是一个注重简单性的测试框架,经过精心设计,旨在带回 PHP 测试的乐趣。
Pest 和 PHPUnit 是什么关系?
简单理解:套壳。类似 Laravel 与 Symfony 的关系。
集成和开发了一些功能:
Hyperf 项目如何引入 Pest ?
Hyperf 是基于 Swoole/Swow 的协程框架,最大的亮点也是 Coroutine(协程),但是 Swoole 的协程是需要协程环境的(Swow 不需要),也就意味着有些单元测试(TestCase)需要允许在协程环境下,否则会报错。
如:
直接执行,会直接报错。需要套一层协程环境:
这样就不会报错了。但是……每一个都这么“套”一层,挺累的吧。
改造 TestCase
前一步,我们发现每个 Case 都要套一个协程环境,开发体验确实不是特别好,那么我们通过自定义 TestCase 把协程环境自动前置套入到每一个 Case,代码如下:
项目中所有 TestCase 都继承这个类即可。
安装&配置 Pest
前面又是协程环境,又是改造 TestCase,跟 pest 有什么关系?
当然有!除了前面提到的需要支持协程 Case,Pest 还有一个亮点功能:Parallel Testing(并行测试),需要依赖改造过的
TestCase::runTestsInCoroutine
。接下来先安装&配置 pest 吧。
开始 Pest 之旅吧
./vendor/bin/pest --parallel # 制定进程数 ./vendor/bin/pest --parallel --processes=10
Beta Was this translation helpful? Give feedback.
All reactions