Grammars, especially context-free grammars, are widely used within and even outside the field of computer science. In this paper, we present a systematic framework for grammar testing, in which some commonly used techniques for testing programs such as module testing and integration testing are adapted and applied to the testing of grammars. We propose a nonterminal-based approach for grammar modularization, combined with an iterative process for grammar testing in which a grammar is tested with respect to both a generator and a recognizer. Experiments on grammars for some non-trivial programming languages such as C and Java demonstrate the feasibility and efficiency of the testing framework and the proposed approaches.