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:
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 I've only found references to people getting it through doctors that have an existing relationship with the company, so I don't know how a regular consumer would order it.
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.