Recall & Review
beginner
What is the purpose of HTTP test assertions in Laravel?
HTTP test assertions check if your web application's responses behave as expected during automated tests. They help verify status codes, content, redirects, and more.
Click to reveal answer
beginner
How do you assert that a response status is 200 OK in Laravel tests?
Use
$response->assertStatus(200); to check if the HTTP response status code is 200, meaning the request was successful.Click to reveal answer
beginner
What does
$response->assertSee('text') do in Laravel HTTP tests?It checks if the response content contains the given text string. This helps confirm that specific content is visible in the response.
Click to reveal answer
intermediate
How can you test that a response redirects to a specific URL in Laravel?
Use
$response->assertRedirect('/target-url'); to verify the response sends a redirect to the given URL.Click to reveal answer
intermediate
What assertion would you use to check if a JSON response contains a specific structure or data?
Use
$response->assertJson(['key' => 'value']); to verify the JSON response includes the specified key-value pairs.Click to reveal answer
Which Laravel assertion checks if the HTTP response status is 404?
✗ Incorrect
assertStatus(404) verifies the HTTP status code is 404 Not Found.
How do you verify that a response contains the text 'Welcome' in Laravel tests?
✗ Incorrect
assertSee('Welcome') checks if the response content includes the text 'Welcome'.
Which assertion confirms a response redirects to '/home'?
✗ Incorrect
assertRedirect('/home') checks the response redirects to the URL '/home'.
To check if a JSON response has a key 'user' with value 'admin', which assertion is correct?
✗ Incorrect
assertJson(['user' => 'admin']) verifies the JSON response includes that key-value pair.
Which assertion would you use to confirm a response has no errors in Laravel?
✗ Incorrect
assertSuccessful() checks if the response status code is between 200 and 299, meaning no errors.
Explain how to use Laravel HTTP test assertions to verify a page loads successfully and contains specific text.
Think about checking status and visible content.
You got /3 concepts.
Describe how to test JSON responses in Laravel using HTTP test assertions.
Focus on JSON content verification.
You got /3 concepts.