You should take the test before you apply for naturalisation as a British citizen, provided you meet all the other requirements for naturalisation. The Home Office website provides more information on how to apply for naturalisation as a British citizen. If you pass the test, you are given a letter which proves you have been successful. This is called your pass notification letter. You will need to attach your pass notification letter to your filled-in citizenship application form and send both to the Home Office. The Home Office will retain the information it gets from test centres for a reasonable period. However, you should submit your application as soon as possible after taking the test.
From 1 April 2007, you will have to take the test before applying for indefinite leave to remain (settlement).