Magnesium deficiency is diagnosed with a blood test and, in rare cases, a urine test.