IMHO, the ideal time to take the test is as soon as practical after you have completed all the coursework tested on the exam. This has to be balanced against when you intend to apply, because the test expires at a lot of schools as soon as three years after you take it, and the fact that material will become stale the longer you wait to take it after you have taken all the relevant classes.