How long do you have to wait to take a pregnancy test?

I had sex about 3 1/2 weeks ago during my fertile window just wondering when I can take a test or just wait until a missed period before testing ......Thanks in advance!!