A magnesium test is used to measure the level of magnesium in the blood (or sometimes urine). … It also may be ordered when a person has symptoms that may be due to a magnesium deficiency, such as muscle weakness, twitching, cramping, confusion, cardiac arrhythmias, and seizures.