When to take pregnancy test?

How long after sex do I have to wait for a pregnancy test?