Using a study that randomly assigns HIV testing in two sites in sub-Saharan Africa, I examine the effects of testing on sexual behaviour. Using sexually transmitted infections as markers of risky sex, I find behavioural responses to HIV tests when tests provide unexpected information. Individuals surprised by an HIV-positive (HIV-negative) test increase (decrease) their risky sexual behaviour. I simulate the effects of testing and find under certain conditions, new HIV infections increase when people are tested. The provision of anti-retrovirals for HIV-positive individuals immediately after testing mitigates these effects and leads to decreases in HIV infections in all cases.