Laravel modules tests not detected in Laravel 10

77 Views Asked by At

I installed Laravel Modules on My Laravel 10 Project. I tested many setting in phpunit for detecting module's tests but phpunit cannot find the tests.

In laravel 8, this setting works for me:

 <coverage processUncoveredFiles="true">
        <include>
            <directory suffix="Test.php">./Modules/**/Tests/Unit/</directory>
            <directory suffix="Test.php">./Modules/**/Tests/Feature/</directory>
        </include>
    </coverage>

But in Laravel 10 coverage tag make error.

With Bellow code, test cannot detect module's tests as well:

<testsuite name="Module Tests">
        <directory suffix="Test.php">./Modules/*/Tests</directory>
    </testsuite>

Or

 <testsuite name="Unit">
        <directory>./Modules/**/Tests/Unit</directory>
    </testsuite>
    <testsuite name="Feature">
        <directory>./Modules/**/Tests/Feature</directory>
    </testsuite>
1

There are 1 best solutions below

0
On

for laravel modules, you can either specify the testsuite one after the other using this approach


    <testsuites>
        <testsuite name="GlobalUnit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="GlobalFeature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
        <testsuite name="CoreModule">
            <directory suffix="Test.php">./Modules/Core/Tests</directory>
        </testsuite>
        <testsuite name="UserModule">
            <directory suffix="Test.php">./Modules/User/Tests</directory>
        </testsuite>
    </testsuites>
    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">./app</directory>
        </include>
    </coverage>
</phpunit>

or using your approach

<testsuite name="Unit">
        <directory>./Modules/**/Tests/Unit</directory>
    </testsuite>
    <testsuite name="Feature">
        <directory>./Modules/**/Tests/Feature</directory>
    </testsuite>

    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">./app</directory>
        </include>
    </coverage>

in the second approach, the suffix was .PHP , this will pick all.