Start broad brushed then narrow

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the testing category.

Last Updated: 2024-04-18

I had the following test and it was failing:

 <? php

 // Ensure that email was sent
 Mail::assertQueued(ReverseAuctionMail::class, function ($mail) use ($nearbyAdvisor) {
   return $mail->hasTo($advisor->email);
 });

I spent half an hour debugging various $advisor emails and hard-coding the variables in the test (e.g. giving the test a specific $advisor email instead of $advisor->email). Still failures.

What I should have done was zoom out and check if the overall email delivery system was intact (rather than whether an email got delivered to a particular someone.)

<? php
Mail::assertSent(ReverseAuctionMail::class, 1); // failed

The failure here revealed that NO emails were sent at all - the delivery system was not working.

Lesson

When incrementally writing tests - especially for a platform you don't understand well, start off with broad-brush tests that test the overall system and only make them narrower with time - otherwise you can end up debugging the wrong thing and losing time.