In the majority of US states you can order magnesium testing online and have the blood drawn at a local blood draw center (see my general overview of the process).
The most common magnesium test is serum magnesium.
I'd suggest ordering from Life Extension because they have the cheapest price I know of ($22), and I've been happy with their service. You can also compare the other 6 magnesium test providers I've found.
Take a look at my state-specific issues page if you're in AZ, MD, NJ, NY or RI.
I haven't personally looked into the issue, but a lot of magnesium supplementation advocates argue for magensium RBC testing instead of serum testing. Here's the providers I found for that, it's typically around 2x the cost of the serum testing:
Magnesium WBC testing might be even better, but I've never found a source for ordering it.
I've only found one place doing urine testing:
Some people argue that this is the best (though also most-expensive) way to test magnesium levels. The only lab I've ever found for it is IntraCellular Diagnostic's EXA Test, but it needs to be ordered by a healthcare provider. They have a patient page where you can ask about potential doctors that could prescribe it. Be warned that it appears to cost about $300, plus the healthcare provider's time for collecting the specimen.
I've got a big ol' collection of pages on magnesium supplementation at my other site. I even tried to look professional for it by wearing a tie in the author photo. Extreme measures, I know.