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
评论列表(0条)