I like to think of grammar rules and the accompanying tests that make you remember them as.. rules you can use to generate any number of examples to better the language.
You learn a language by being exposed to it countless times, but most of us doesn't have the opportunity to be immersed 100% into a foreign language. Simple rules let us try out new sentences and do some self-checks to cull out the definitely wrong ones.
This makes your "training set" significantly larger without having to "collect that data". Of course it doesn't replace anything, but it is a useful part of the language learning journey, especially the early part. Later on, nothing can replace simple exposure.