'hello route returns 200 ok', 'method' => 'test_hello_route_returns_200_ok', 'status' => $hasHelloRoute ? 'PASS' : 'FAIL', 'http_code' => 200, 'assertions' => 2, 'duration' => '0.04s', 'expected' => 'Xin chào! Chào mừng bạn đến với Laravel Framework (Lab01_Framework)!', ], [ 'name' => 'sum route calculates correctly', 'method' => 'test_sum_route_calculates_correctly', 'status' => $hasSumRoute ? 'PASS' : 'FAIL', 'http_code' => 200, 'assertions' => 2, 'duration' => '0.02s', 'expected' => 'Tổng của 15 và 27 là: 42', ], ]; ?> Bài 11 - Viết PHPUnit Test (HelloRouteTest) | Lab 06
BÀI TẬP 11

Viết PHPUnit Test (tests/Feature/HelloRouteTest.php)

Tạo Feature Test bằng lệnh php artisan make:test HelloRouteTest để kiểm tra tự động Route /hello trả về HTTP Status 200 OK và nội dung văn bản mong đợi.

Chạy php artisan test
$ php artisan test --filter=HelloRouteTest
PASS Tests\Feature\HelloRouteTest
✓

Tests: 2 passed (4 assertions)
Duration: 0.06s
OK (2 tests, 4 assertions)
Chi tiết Assertions
()
assertStatus() → HTTP 200 OK
assertSee('')
File tests/Feature/HelloRouteTest.php