PHPUnit print tests execution time

前端 未结 9 1403
天涯浪人
天涯浪人 2021-02-11 21:04

is there a way to print the execution time of each test with PHPUnit?

9条回答
  •  说谎
    说谎 (楼主)
    2021-02-11 21:49

    If you don't like to write a Testlistener, like it was suggested already, you can use the following script to parse the PHPUnit's JSON Test Result in an easier to read format:

    alias phpunit-report-runtime="phpunit --log-json php://stdout \
        | awk '\$NF ~ '/,/' && \$1 ~ /\"(test|time)\"/' \
        | cut -d: -f2- \
        | sed \"N;s/\n/--/\"  \
        | sed \"s/,//\"   \
        | awk 'BEGIN{FS=\"--\"}; {print \$2 \$1}' | sort -r \
        | head -n 5"
    

    Format is . Example output:

     $ phpunit-report-runtime
     0.29307007789612, "VCR\\Util\\SoapClientTest::testDoRequestHookDisabled"
     0.16475319862366, "VCR\\CassetteTest::testRecordAndPlaybackRequest"
     0.092710018157959, "VCR\\Util\\SoapClientTest::testDoRequest"
     0.031861782073975, "VCR\\LibraryHooks\\SoapTest::testShouldInterceptCallWhenEnabled"
     0.026772022247314, "VCR\\LibraryHooks\\AbstractFilterTest::testRegisterAlreadyRegistered"
    

提交回复
热议问题