A magnesium test determines the level of magnesium in the blood. Magnesium is a mineral that aids in the proper functioning of muscles, nerves, the immune system, and the heart. It also aids in the production of protein and energy, as well as the maintenance of bone strength.