When we take substances into our body, whether food or drugs, our body breaks those substances down into parts that we can use to fuel, change, or otherwise affect our body processes. The by-products of those processes are called metabolites, and they are removed from the body via urine.
When specific substances - illegal drugs for example - are metabolized, they leave specific metabolite footprints in the person’s urine for a period of time. If the urine is tested during that time-frame from a collections facility, the urine drug test can reveal the presence of these metabolites and, therefore, the occurrence of drug use (the quantity of the drug present is not measured).