Computer models of different strategies for the management of dyspepsia in primary care indicate that a 'test-and-treat' approach is likely to be associated with the lowest costs and acceptable clinical outcomes. We present information on computer modelling studies and report the findings of a randomised trial comparing a Helicobacter pylori test-and-treat strategy with referral to direct access endoscopy in the management of dyspepsia in general practice. We compared costs and clinical outcomes in patients managed for one year in study (test-and-treat) and control (endoscopy) practices in south London. Patients aged less than 45 years presenting with persistent dyspepsia without alarm symptoms (141 study patients, 91 control patients) were studied. In the one-year follow-up period there were 17 endoscopies in the study group: all the control patients underwent initial endoscopy and five further endoscopies were performed. None revealed peptic ulcer or cancer. Forty-three (30%) of the study patients compared with 16 (17%) of the controls were referred to hospital clinics (p < 0.025). The cost of management per patient for one year in the study group was 205.67 Pounds, compared with 404.31 Pounds in the control group (p < 0.0001). Clinical outcomes in both groups at one year were comparable. An H. pylori test-and-treat strategy for dyspeptic patients aged less than 45, employing office-based serology testing, appears to be associated with substantially lower costs than initial endoscopy and with similar clinical outcomes.