magnesium test is used to measure the level of magnesium in the blood (or sometimes urine). Abnormal levels of magnesium are most frequently seen in conditions or diseases that cause impaired or excessive excretion of magnesium by the kidneys or that cause impaired absorption in the intestines.