If you've had long-standing heartburn, your doctor may order a test called an endoscopy to evaluate for signs and symptoms of something called gastroesophageal reflux disease. Endoscopy is a painless procedure that usually takes place in the morning. The preparation for endoscopy usually involves fasting after midnight the night before the test.