【发布时间】:2019-10-16 09:39:34
【问题描述】:
有一个带有测试套件的 Laravel 应用程序可以在大约 3 分钟内完全运行。
大约 2 分钟后,测试冻结了约 60094 毫秒。每次都是不同的测试,所以它似乎与任何特定的测试无关。
没有一个测试失败,他们只是经历了这种奇怪的延迟。 什么可能导致 PhpUnit 延迟 60 秒?
You should really fix these slow tests (>200ms)...
1. 60094ms to run Tests\Feature\Superadmin\BusinessActivityTest:testDestroyBusinessActivityProductionProcess
2. 3357ms to run Tests\Feature\AccessTokenTest:testOauthToken
3. 1124ms to run Tests\Feature\Superadmin\ArticleTest:testUpdateArticleForAdmin
4. 969ms to run Tests\Feature\VtaDocumentTest:testUploadVehiclesFileHappyPathWithFilePDF
5. 737ms to run Tests\Feature\VtaDocumentTest:testUploadCertificateFilePDF
...and there are 22 more above your threshold hidden from view
Time: 2.46 minutes, Memory: 144.25MB
操作系统 phpunit 版本 phpunit -v Sebastian Bergmann 和贡献者的 PHPUnit 7.3.0。 运行时:PHP 7.3.5-1+ubuntu18.04.1+deb.sury.org+1 和 Xdebug 2.7.1
问题也存在 供应商/bin/phpunit --version Sebastian Bergmann 和贡献者的 PHPUnit 7.5.2。
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_DATABASE" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
</php>
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
<arguments>
<array>
<element key="slowThreshold">
<integer>200</integer>
</element>
<element key="reportLength">
<integer>5</integer>
</element>
</array>
</arguments>
</listener>
</listeners>
</phpunit>
【问题讨论】:
-
有任何代码可以链接到吗?还是我真的对您在这里问的内容感到困惑?
-
添加了样本测试结果。每次运行 60000+ 毫秒的测试都是不同的。测试需要很长时间在时间上或多或少相同的位置。
-
您使用的是哪个 Phpunit 版本,您是否为 Phpuni 测试套件使用了任何其他扩展?
-
添加了 phpunit 版本和配置。删除 SpeedTrapListener 并不能避免 60 秒的等待。
-
您是否尝试过打开/跟踪您的 test.log 以查看是否可以在其中找到任何有用的信息?
标签: php unit-testing phpunit