unit testing - Pest tests in Laravel 11 returns 404 - Stack Overflow

I have generated a new project. It is mainly an API and I want to add tests with Pest.I am using Sail

I have generated a new project. It is mainly an API and I want to add tests with Pest. I am using Sail for local development and I run the tests through the containers (sail artisan test).

The problem that only the first test that is executed finds the indicated route, even if they are the same. The second tests returns a 404 error from the ->get()

I have these two tests:

it('test 1', function () {
    $this->get('api/v1/home')->assertStatus(200);
});

it('test 2', function () {
    $this->get('api/v1/home')->assertStatus(200);
});

and this is the result:

sail artisan test

FAIL  Tests\Feature\Api\Home\HomeControllerTest
✓ it test 1                                                                                                                                                                                                 
⨯ it test 2 <-- Error 404

if I run one by one, it works without problems:

sail artisan test --filter="Test 1"

PASS  Tests\Feature\Api\Home\HomeControllerTest
✓ it test 1 
sail artisan test --filter="Test 2"

PASS  Tests\Feature\Api\Home\HomeControllerTest
✓ it test 2  

Out of curiosity, I ran the same test in PHPUnit, and it works without any problem.

Would anyone have any idea what could be the reason that the same test in the first run, works correctly (200) but in the second run it does not find the route (404)?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745659800a4638765.html

相关推荐

  • unit testing - Pest tests in Laravel 11 returns 404 - Stack Overflow

    I have generated a new project. It is mainly an API and I want to add tests with Pest.I am using Sail

    21天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信