When should I take the test?

You should take the test when you are ready to apply for naturalisation or settlement. Test results are valid for an indefinite period however Home Office states they will keep the test results for a reasonable period so taking it too early may cause problems.
http://www.lifeintheuktest.me.uk/?page_id=11

also there was some gossip a while ago the gov was thinking of making it valid for 2yrs,

so apply early but maybe not tooo early