You should urgently apply for settled status. ILR means nothing anymore (except it means that you will get settled status without problems). If you don't have settled status by the end of 2020, you are in trouble. Even if you could have got settled status without problems if you only had applied.
Apart from that, you must have evidence that you passed the "life in the UK test" before you can apply for citizenship. You can't pass the test or fail the test after you apply. So the problem that you fear doesn't happen.
The test itself is £50. Refundable if you cancel more than three days before the test; if you cancel too late or fail the test your £50 is gone. You have to wait a week before you can take the test again. You get booklets with all questions, around 1000, and you need to get 18 out of 24 right. It's tricky without preparation, so prepare (they say less than 50% of 18 year old Brits would pass). I'd say get an app for training and take the test when you pass 10 training tests in a row.
(PS. I mentioned settled status because apparently many EU citizens who live in the UK haven't applied yet. Some because they incorrectly believe they don't need to. For example pensioners who lived in the UK for 50 years, children whose parents need to apply for them, and EU citizens having permanent residence status. )