How do tests tell if you have stomach ulcers?

Endoscopy. Has largely replaced less clear contrast barium swallows. Also, tests for helicobacter pylorii can be done.