Like every other skill, grammar can be improved by acquiring more grammatical knowledge by learning grammar and practising it continuously until you are good enough to write the test.