Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Building Web Apps with Laravel Module 12

Testing Laravel applications interview questions

Interview questions on testing Laravel applications: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.

15 questions: 4 warm-ups and 11 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    In a Laravel project, how does a unit test differ from a feature test, and which kind should most tests be?

    Answered in the lesson Testing with Pest and PHPUnit

  2. Fresher to mid

    Why does the second test of a class find the students table empty after the first test created a student?

    Answered in the lesson HTTP tests and database tests

  3. Fresher to mid

    How does a fake differ from a mock in a Laravel test?

    Answered in the lesson Fakes, mocks and time travel

  4. Fresher to mid

    What can static analysis find in a Laravel app that its feature tests miss?

    Answered in the lesson Browser tests, static analysis and CI

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to mid

    A developer ran a deployment script on their laptop to try it out. Afterwards, php artisan test passed as usual, but their local database was empty. Explain what most likely happened and what you would change so that it cannot happen again.

    What it tests
    Knowing that a cached configuration replaces the testing values of phpunit.xml, that RefreshDatabase rebuilds whatever database the configuration names, and which guards stop it.
    First step
    Ask what the script ran: a deployment usually runs php artisan config:cache. Then check whether bootstrap/cache/config.php exists, and run one test that prints app()->environment() and the database name.
    Follow-ups

    From the lesson Testing with Pest and PHPUnit

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  2. Mid to senior

    Your team wants to move a Laravel 13 project's 400 PHPUnit tests to Pest. Production runs PHP 8.3 today and moves to PHP 8.4 next quarter. Plan the move: which versions, which commands, in what order, and how you prove that no test was lost on the way.

    What it tests
    Reading version constraints (Pest 4 on PHPUnit 12.5.33, Pest 5 on PHPUnit 13 and PHP 8.4), using drift safely, and comparing test and assertion counts before and after.
    First step
    Write down the constraints first: the PHP version of every place the tests run, and the PHPUnit version the project locks. They decide whether Pest 5 is possible now or only after the PHP upgrade.
    Follow-ups

    From the lesson Testing with Pest and PHPUnit

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Mid to senior

    A code review finds that a Laravel endpoint listing each family's fee instalments has returned the guardian's phone number in every item for weeks, while all of its tests stayed green. Explain how the tests missed it and what you would change in the tests and in the code.

    What it tests
    Knowing which JSON assertions check single values and which check a whole object, and treating every field an endpoint returns as a decision made in the code and pinned by a test.
    First step
    Read the endpoint's tests and list what each one asserts about the response. Then compare that list with every key a real response carries: any key that no test mentions is a field the suite cannot see.
    Follow-ups

    From the lesson HTTP tests and database tests

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  4. Fresher to mid

    After a redesign of the instalment form, staff get a 419 Page Expired page every time they save, yet every feature test of the form stays green. Explain why the tests could not catch it, and which test you would add so that it cannot happen again.

    What it tests
    Knowing what a 419 means in Laravel, how the CSRF check behaves while tests run, and the difference between testing the framework's middleware and testing your own page.
    First step
    Open the form's page in the browser's developer tools and look for a hidden _token field inside the form and a session cookie on the response. A 419 means the token was missing or did not match, so decide which of the two it is before you change anything.
    Follow-ups

    From the lesson HTTP tests and database tests

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  5. Mid to senior

    A Laravel project has 600 passing tests and 85 % line coverage, yet two bugs in fee calculations reached production within a few months. How would you measure how good the suite really is, and how would you turn the result into better tests?

    What it tests
    Knowing what line coverage does and does not prove, how to measure whether tests notice deliberate mistakes, and how each mistake they miss becomes the next test.
    First step
    Take one of the two escaped bugs and put it back on a branch, then run the suite. If every test stays green, the suite cannot see that kind of mistake, and the real question becomes how many more like it exist.
    Follow-ups

    From the lesson HTTP tests and database tests

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  6. Mid to senior

    After a deploy, some guardians got the same fee reminder SMS twice on one morning, yet every reminder test is green. How would you find the cause, and which tests would you add so that it cannot happen again?

    What it tests
    Knowing what makes a scheduled command safe to run twice, how a mock's once() and a fake's assertSentTimes() count sends over two runs, and why a test of one run cannot see a second.
    First step
    Count how many times the command ran that morning: the scheduler's log, the deploy's own steps and any manual run. Then read what stops a second run from sending again, such as a reminded_at column that the query checks.
    Follow-ups

    From the lesson Fakes, mocks and time travel

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  7. Fresher to mid

    A reminder test fails in the nightly CI run at 02:00 IST and succeeds every time a developer runs it during the day. Nobody changed the code. Explain the most likely cause and how you would make the test deterministic.

    What it tests
    Recognising a test whose result depends on the time of day, working out which clock and calendar the test and the code each read, and making the test give one answer at any hour.
    First step
    Read how the test builds its dates and how the code builds its own, and write down which clock and which timezone each one reads. A difference between the two is the first place to look.
    Follow-ups

    From the lesson Fakes, mocks and time travel

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  8. Mid to senior

    Every feature test of a payment flow is green with Bus::fake(), yet in production the job that copies payments into the ledger fails on every payment. How did the suite miss it, and how would you change the tests?

    What it tests
    Knowing what a bus or queue fake records and what it never runs, and how to test the code of a job that every feature test fakes.
    First step
    Read the job's error in the failed jobs table, then look for a test that calls that job's handle(). If every test fakes the bus, no test has ever run the job's code.
    Follow-ups

    From the lesson Fakes, mocks and time travel

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  9. Mid to senior

    Every feature test of a Laravel app is green, yet a queued job crashed in production on its first run with a call to an undefined method. Which checks would you add to the project, and where would each run, so that the next mistake of this kind stops before the merge?

    What it tests
    Knowing what a faked queue hides, what static analysis can show without running code, how to bring it into an existing project, and how CI makes every check unavoidable.
    First step
    Start with why no test ran the job: look for Bus::fake() or Queue::fake() in the tests that dispatch it, and for a test that calls the job's own handle(). Then run Larastan on the job's file and read what it reports.
    Follow-ups

    From the lesson Browser tests, static analysis and CI

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  10. Mid to senior

    A Dusk test creates a student with a factory, opens the student's page in Chrome and sees an empty list. The same steps written as an HTTP test are green. What is the most likely cause, and how would you fix the browser test?

    What it tests
    Understanding how a browser test reaches the application, where the rows a test writes are visible, and which database reset fits each kind of test.
    First step
    Compare where the rows are written with where the page reads them: which connection and which transaction the test uses, and which process answers the request that Chrome sends.
    Follow-ups

    From the lesson Browser tests, static analysis and CI

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  11. Mid to senior

    composer.json says php ^8.3, so a pull request adds PHP 8.3 to the CI matrix. The 8.3 job fails at composer install while the 8.4 and 8.5 jobs are green. Explain what happened and the options you would give the team.

    What it tests
    Knowing that composer install takes its versions from the lock file, how to find what blocks an older PHP, and how to make the lock, the matrix and the servers agree.
    First step
    Read the failing step's error first: it names a package and the PHP version that package needs. Then compare what composer.json allows with what composer.lock actually holds.
    Follow-ups

    From the lesson Browser tests, static analysis and CI

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All Building Web Apps with Laravel interview questions · The Building Web Apps with Laravel track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.