Using Groovy in Testing

From CitconWiki
Jump to navigationJump to search

The bulk of the session introduced the Groovy language.

Benefits of using Groovy for writing developer tests were summarised as:

  • Test code is shorter and sweeter (than Java)
  • You can use GroovyConsole or the interactive shell (groovysh) to try things out live
  • JUnit 3.8 built-in
  • Powerful assertion capability built-in to Groovy (though for JUnit4 assertions, you need to use static imports)
  • JUnit 4 support including Parameterized tests and Theories: Groovy Doco
  • TestNG support
  • Full Java library support
  • Built-in support making it easy to parse XML and access databases for data-driven tests
  • Groovy's built in mocking is easy to use (but often you can get by with Closures, maps or expandos)
  • Groovy is great for creating testing DSLs
  • Groovy's fun!!

To use as a JUnit test, the simplest way is to extend GroovyTestCase. With the Groovy plugins installed, you can use Groovy JUnits in the same way as Java JUnits.