-
Book Overview & Buying
-
Table Of Contents
Grails 1.1 Web Application Development
By :
Unit testing in Groovy, and therefore Grails, is based on the JUnit (http://www.junit.org) test framework. We will quickly review how to use this framework before getting into unit testing in Grails. JUnit allows developers to write tests that validate their code, by exercising the code, and performing assertions on the state of the code at a given point. Tests are implemented as methods in a class, and each test method equates to a distinct test.
Since JUnit 4, there are two ways to declare tests and test classes. Groovy and Grails use the original convention based approach that was used before annotations were made available in Java. Pre JUnit 4 tests are defined as follows:
A test class must extend the TestCase class
Test methods within a test class must:
be declared as public
have a return type of void
accept no arguments
the name of the method must begin with the word test
Here is a simple Java example that performs a test on the String class.
package example; import junit...
Change the font size
Change margin width
Change background colour