drngnh708353 2015-03-27 11:03
浏览 545
已采纳

PHPUnit - 使用配置文件时'没有执行测试'

The Problem

To improve my quality of code, I've decided to try to learn how to test my code using Unit Testing instead of my mediocre-at-best testing solutions.

I decided to install PHPUnit using composer for a personal library that allows me to achieve common database functions. At first I didn't have a configuration file for PHPUnit and when I ran commands like:

$ phpunit tests/GeneralStringFunctions/GeneralStringFunctionsTest

Please note that this is a terminal command, so I didn't include the .php extension. The GeneralStringFunctionsTest referred to above is actually a GeneralStringFunctionsTest.php file.

The output is what I expected:

Time: 31 ms, Memory: 2.75Mb

OK (1 test, 1 assertion)

I then tried to use a configuration file to automatically load the test suite instead of having to manually type in the file every time. I created a file called phpunit.xml in my root directory, and entered the following into the file: http://pastebin.com/0j0L4WBD:

<?xml version = "1.0" encoding="UTF-8" ?>
<phpunit>
    <testsuites>
        <testsuite name="Tests">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

Now, when I run the command:

phpunit

I get the following output:

PHPUnit 4.5.0 by Sebastian Bergmann and contributors.

Configuration read from /Users/muyiwa/Projects/DatabaseHelper/phpunit.xml

Time: 16 ms, Memory: 1.50Mb

No tests executed!

In case it's helpful, my directory structure is as follows:
src - Top level directory (with all my source code)
tests - Top level directory (with all my tests, structured the same as my src folder)
vendor - Composer third party files

I also have the composer json and lock file, as well as the phpunit xml file in the top level as files.

Things I've Tried

  • Changing the directory in phpunit.xml to tests/GeneralStringFunctions
  • Changing the directory in phpunit.xml to ./tests
  • Moving the phpunit.xml file to the tests directory and then changing the directory to be ./ instead of tests.
  • Adding a suffix attribute to the directory tag in phpunit.xml to specify "Tests" as the explicit suffix.
  • 写回答

16条回答 默认 最新

  • duanmei1350 2017-02-15 21:46
    关注

    For what it's worth (being late), I ran into this recently while I was making a new Laravel 5.1 project for a simple website. I tried to debug it and was confused when I tried:

    php artisan make:test homeTest
    

    (which has a default test that just asserts true is true)

    and saw the output

    No tests executed!
    

    What the problem ended up being for me was related to my PHP installation -- "phpunit" was globally registered and configured differently, whereas the phpunit that came with the Laravel installation was configured just right and ran perfectly.

    So the fix is running the vendor's configured phpunit (from the same root directory as app/ and tests/):

    ./vendor/bin/phpunit
    

    Hope that helps someone else!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(15条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog