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. I only found references to a company called EXA Test providing it to consumers, but their web site appears to be gone, making me think they've gone out of business. Please let me know in the comments if you know of other sources.
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.