swoft icon indicating copy to clipboard operation
swoft copied to clipboard

单元测试该怎么写,有没有详细一点的demo

Open tianya441523 opened this issue 4 years ago • 7 comments

看了一下官方文档,完全没找到单元测试的那块内容。在swoft的test中找到文档,提示用php test/run.php -c phpunit.xml --testsuite unitTests 但没有详细的demo教程,能不能出一份呢?

tianya441523 avatar Nov 05 '20 07:11 tianya441523

运行单元测试中/** * @Inject() * @var AccessLogService */ 注入的不能正确加载,提示为null

phpwei avatar Nov 06 '20 03:11 phpwei

Error: Call to a member function test() on null

phpwei avatar Nov 06 '20 03:11 phpwei

[ERROR] Coroutine internal error: The pool of App\Model\Entity\Users entity is not defined or empty At File /data/api/vendor/swoft/db/src/EntityRegister.php line 175

phpwei avatar Nov 09 '20 12:11 phpwei

看看 Travis ci 脚本就知道了 框架自己有单元测试的

sakuraovq avatar Jan 29 '21 15:01 sakuraovq

好的,最近我们争取把单元测试的文档补上。

XuanYi2018 avatar Apr 30 '21 15:04 XuanYi2018

@phpwei 我也遇到了,请问您解决了吗

zch513430014 avatar Aug 12 '21 08:08 zch513430014

https://github.com/swoft-cloud/swoft-components 可以看各个组件的单元测试

例如 http-server 的测试: https://github.com/swoft-cloud/swoft-component/tree/master/src/http-server/test/unit

swoft 里面也提供了测试示例的 https://github.com/swoft-cloud/swoft/tree/master/test

inhere avatar Aug 12 '21 12:08 inhere