Most experts recommend waiting to be tested until three months after having sex that put you at risk. That's because it may take that long to develop antibodies that can be found by testing. There are, though, some newer tests that may provide results sooner. Discuss your timing for having tests with your doctor.
It's important to avoid risky behaviors during that three-month period. If you think you are infected, see a doctor right away. He or she can help guide you in the testing.