Since I still hear about people dying from adverse effects of anesthesia, prescription drugs, and clinical trials, we obviously don't have a perfect ex vivo test for adverse reactions to arbitrary drugs. But what DO we have, how effective are they, and are there any up-and-coming techniques in research?
The only way to know if a drug is going to kill you, or have a serious side affect is to take it and see what happens. However, there are usually many ways to predict risk of such reactions. Researchers do their best to figure this out in the drug development and testing stage, so each drug that get's approved will come with a list of contraindications (conditions that have been determined to put you at greater risk of the side effects).
There's no such thing as a general drug safety test - nor could there ever be, since each potentially deadly reaction happens in it's own way. Researchers do attempt to identify the mechanism behind serious drug reactions. Once that mechanism is identified, then they are sometimes able to develop tests for susceptibility to that particular mechanism, but this is typically on a case by case basis. In some cases, a particular mechanism might apply to a whole class of drugs so one test can help predict a potential negative affect to any drug in the class.
There are various risks associated with anesthesia - all of which are very rare. They include interactions with other drugs and conditions, as well as human error (overdose, etc.). One significant cause of death directly due to a reaction to anesthesia itself is due to something called malignant hyperthermia. The first manifestation of this is typically in the operating room, so it's difficult to predict. It seems the only approved test involves a muscle biopsy (they have to take a cell sample from a muscle), so this is only done if you have a family history of the condition. Research on less invasive tests is ongoing and promising, including a genetic test and an injection test
Many drug reactions (including some deadly ones) fall under the category of what you know as an 'allergy'. Often times these reactions can be tested with a skin or blood test.
Other types of reactions
This list can go on and on, so I'll just refer the interested reader to a paper that does a much better job than I could: Adverse Drug Reactions: Types and Treatment Options