How do I know when to test and get an accurate result?

My next period is in like 5-7 days, unless ow I’m pregnant, obviously. Can I test before that? Or do I have to wait until I’m late?