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.
Having such a bad reaction to it lead me down a wild goose chase toward finding out the way my body processes serotonin ala a gene test, helped me figure out what was causing the depression to begin with.
Another reply here talks about how it seems to be a crapshoot for finding effective drugs and a lot of trial and error. I think that there may be promise in doing drug targeting genetic tests and possibly microbiome sampling as a way to help people avoid the run-around. In my case, knowing this ahead of time would have helped me avoid a lot of suffering and 3 years of obsessively searching for answers.