Can doctors differentiate between ulcers causes by stress vs nsaids? Like in tests

Possible. Nsaids tends to worsen any ulcer but tends to induce multiple ulcers. Otherwise ulcer usually affects one or two areas. The diagnosis however would be primarily based on the history. Another common cause for ulcer is h pylori infection.
No. There is usually no way to tell whether an ulcer is stress-related or caused by nsaid's except by the info u give. Some blood tests such as for h. Pylori can let your dr. Know if you have a bacterial infection in your gut that can predispose you to developing ulcers which can occur in your intestines ; less commonly in your stomach. Stomach ulcers are more related to NSAID use.
History determines. Although there are subtle differences in terms of location, distribution, appearance based on cause of ulcer(s), etiology (once an ulcer is confirmed) is better determined by a well-taken patient history--e.g. Timing of stressors or use of nsaid's with ulcer symptom onset.