You can test when your period is due OR no sooner than two week after having sex. It takes time for the hCG levels to rise high enough to be detected.
Even then, false negatives are very common. A false positive is very rare.
Use your first morning urine, your wake up pee, for the best accuracy.