Yes you need to take the test before getting ILR (Indefinite Leave to Remain). The purpose of the test is supposedly to familiarise yourself with British Life and Culture (well that's what the UK government think). Best thing is to get the official books and try some of the tests on the internet to prepare yourself. It's not easy to pass as you need to correctly answer 18 out of 24 questions. This might help answer some of your questions:-
https://www.gov.uk/life-in-the-uk-test/overview
You have plenty of time to prepare, but it's advisable to get it over with rather than leave it till the last minute. BUT make sure you prepare because most of the questions even us British find difficult to answer.