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
版权声明:本文标题:unit testing - Pest tests in Laravel 11 returns 404 - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745659799a2161819.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论