pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.06k stars 313 forks source link

[Bug]: No tests found when filter group with phpunit testcases #1165

Closed huangdijia closed 3 weeks ago

huangdijia commented 1 month ago

What Happened

>./vendor/bin/pest --group=mygroup

 INFO  No tests found.

How to Reproduce

// Pest.php
uses()->group('mygroup')->in('MyGroup');
> tree tests
tests
├── MyGroup
│   ├── ExampleTest.php
│   └── UnitTest.php

ExampleTest.php and UnitTest.php is the cases of PHPUnit.

Sample Repository

No response

Pest Version

v2.34.7

PHP Version

8.1.28

Operation System

macOS

Notes

No response

soleinjast commented 3 weeks ago

The issue you're facing is due to the way Pest and PHPUnit handle grouping for test cases. The line uses()->group('mygroup')->in(DIR.'/MyGroup'); in Pest.php is intended to apply Pest's grouping mechanism to all Pest tests in the specified directory. However, it does not automatically apply to PHPUnit tests unless they explicitly use the @group annotation.

Solution To ensure your PHPUnit tests are recognized as part of the mygroup group, you need to explicitly add the @group annotation to your test methods. Here is how you can structure your test case:

Example:

use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase
{
    /**
     * @group mygroup
     */
    public function test_the_application_returns_a_successful_response()
    {
        $this->assertTrue(true);
    }
}