Objective To determine the cost effectiveness of a strategy of near patient Helicobacter pylori testing and endoscopy for managing dyspepsia. Design Randomised controlled trial. Setting 21 UK primary care centres. Participants 478 patients under 50 years old presenting with dyspepsia of longer than four weeks duration. Interventions Near patient testing for H. pylori and open access endoscopy for patients with positive results. Control patients received acid suppressing drugs or specialist referral at general practitioner's discretion. Main outcome measures Cost effectiveness based on improvement in symptoms and use of resources at 12 months; quality of life. Results 40% of the study group tested positive for H pylori. 45% of study patients hall endoscopy compared with 25%, of controls. More peptic ulcers were diagnosed in the study group (7.4% v. 2.1% P = 0.011). Paired comparison of symptom scores and quality of life shelved that all patients improved over time with no difference between study and control groups. No significant differences were observed in rats of prescribing, consultation, or referral. Costs were higher in the study group (pound 367.85 v pound 253.16 pet patient). Conclusions The "test and endoscopy" strategy increases endoscopy rates over usual practice in primary care. The additional cost is not offset by benefits in symptom relief or quality of life.