Urine tests detect toxic substances through various methods, including chromatography and mass spectrometry. These techniques can identify the presence of specific metabolites, which are byproducts formed when the body breaks down drugs and toxins. The identification and quantification of these metabolites help in determining recent exposure to specific substances.