LARAVEL Quality Control & Assurance 2 — Questions and Answers
Question 1: Which Laravel testing method asserts that a JSON response contains a specific key with an exact value?
- assertJsonPath (Correct answer)
- assertJsonFragment
- assertJsonMissing
- assertJsonCount
Correct answer: assertJsonPath
assertJsonPath checks that the response JSON at a given dot-notation path equals the expected value.
Question 2: What does the `RefreshDatabase` trait do differently from `DatabaseTransactions` in Laravel tests?
- It migrates and rolls back the whole database between tests (Correct answer)
- It uses transactions to undo changes after each test
- It seeds the database before every test class
- It disables foreign key checks during tests
Correct answer: It migrates and rolls back the whole database between tests
RefreshDatabase re-migrates the database each test run, while DatabaseTransactions wraps each test in a rolled-back transaction.
Question 3: In Laravel Dusk, which method waits for a Vue or React component to finish rendering before asserting?
- waitFor (Correct answer)
- pause
- waitUntilMissing
- assertVisible
Correct answer: waitFor
waitFor pauses execution until a given selector appears in the DOM, accommodating async rendering.
Question 4: Which Artisan command generates a dedicated model factory class in Laravel 8+?
- make:factory (Correct answer)
- make:seeder
- make:model --factory
- factory:make
Correct answer: make:factory
php artisan make:factory creates a standalone factory class in the database/factories directory.
Question 5: What is the purpose of `$this->withoutExceptionHandling()` in a Laravel feature test?
- Lets exceptions propagate instead of being caught by Laravel's handler (Correct answer)
- Disables all middleware for the request
- Suppresses validation error responses
- Enables verbose logging during the test
Correct answer: Lets exceptions propagate instead of being caught by Laravel's handler
withoutExceptionHandling tells Laravel not to catch exceptions, so test failures show the real stack trace.
Question 6: Which PHPUnit annotation is used to run a single test method multiple times with different data sets in Laravel tests?
- @dataProvider (Correct answer)
- @depends
- @group
- @covers
Correct answer: @dataProvider
@dataProvider links a test method to a method that returns arrays of argument sets, running the test once per set.
Question 7: Which Laravel facade is faked in tests to prevent actual queue jobs from dispatching?
- Queue (Correct answer)
- Bus
- Event
Correct answer: Queue
Queue::fake() intercepts dispatched jobs so you can assert they were pushed without actually processing them.
Which Laravel testing method asserts that a JSON response contains a specific key with an exact value?