An endoscopy is the most common test for diagnosing gastrointestinal bleeding. During an upper GI endoscopy, a thin, lighted tube called an endoscope is inserted through the mouth. It examines the esophagus, stomach and duodenum.