admin管理员组

文章数量:1026989

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)?

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)?

本文标签: unit testingPest tests in Laravel 11 returns 404Stack Overflow