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.
If you get a suspiciously high level from a serum magnesium test, it might be worth asking for a retest. It's one of the tests that can easily be affected by problems (hemolysis) during the blood draw.
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 haven't found any sources for ionized magnesium testing. If you know of any, please leave a comment below.
If you're looking for ionized mangesium testing because of Dr. Carolyn Dean's recommendation, she's now suggesting RBC testing (above) as a "second best" easier-to-find option.
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.