On the other hand it can take 4-6 weeks to see if someone responds to a drug, and the drug can cause adverse events in addition to not treating the disease
So in this case it is cheaper, faster and safer to take the test before prescribing
The most obvious example of such would be the significant number of people who experience suicidal ideation or commit it/make attempts as a result of going on certain medications.
But at the less extreme end, you're likely looking at least a month or two, more likely 3 or 4 for each medication attempt. That's going on, taking it for long enough to have an effect, going back off, repeat.
With how severe the side effects can be for many, that's enough time to lose a job, fail out of college, etc. And you're asking them to potentially spend years in that cycle to maybe fine something that works.
But harsh side effects seem like they would be acceptable if depression is as problematic as you claim.