Many stomach ulcers are caused by an infection with a bacteria called H. pylori. Along with an evaluation of your symptoms and medical history, your doctor will test for a stomach ulcer with a blood, stool, or breath test for H. pylori. Your doctor might want also order an endoscopy. During an endoscopy, a thin tube with a tiny camera is passed down your throat and into your stomach so your doctor can see whether there's an ulcer.