A barium swallow test may be done to look for and diagnose problems in the pharynx and esophagus. You may need a barium swallow test if your healthcare provider thinks that you have: Cancer of the head and neck, pharynx, or esophagus. Hiatal hernia.