HIV - if you think you contracted HIV in the last 72 hours you should visit a GUM clinic immediately. Otherwise you need to wait 6 weeks before testing or it may not show in the results.
Hepatitis B and C, and syphilis - because it can take up to 6 months for these infections to show up during testing, if you test before then and get a negative result, you should test again after a 6 month period.
Herpes, trichomoniasis, mycoplasma, ureaplasma, or gardnerella - it takes at least 4 weeks for one of these infections to show when testing so if you think you've contracted it at some point, wait until 4 weeks afterwards to test.
There is a very small chance that these infections may not be detected by a test if they were acquired recently, so if you get a negative result you should get tested 6 weeks after the incident to make sure that any recent infections are detected.