Tuesday, March 31, 2009

Grails code example: Integration testing quartz job

Here's a quick snippet to use to integration test a quartz job.
I couldn't find a clear example after a quick Google so hopefully this is useful.
There's a good chance that there's a better auto-magical way to get the job injected but I haven't poked through the testing code to work it out :)
package au.com.refactor

class TempCleanerJobTests extends GrailsUnitTestCase {

  def tempCleanerJob
  def grailsApplication

  protected void setUp() {
    super.setUp()
    tempCleanerJob = grailsApplication.mainContext.getBean(TempCleanerJob)
  }

  protected void tearDown() {
    super.tearDown()
  }

  void testCleanNothing() {
    tempCleanerJob.execute()
  }

}

Monday, March 30, 2009

Grails WebTest Plugin 1.1.2 Released

I've just released the latest version of the WebTest plugin for Grails. This was an update to fix a couple of issues with interactive mode use and parameter parsing and to de-couple the WebTest distribution zip. Highlights
  • run-webtest now supports -headless to stop the Swing progress gui being shown during test runs (this was previously possible via system properties, this is just a tidy up)
  • install-plugin webtest will now prompt you to download WebTest (currently version 3). It installs it into your .grails directory by default or you can answer 'n' and manually set the install location via webtest/conf/webtest.properties using wt.config.home

Tuesday, February 24, 2009

Grails WebTest Plugin 1.1.1 Released

I've released an updated version of the WebTest plugin which is compatible with Grails 1.1.
It also has the latest WebTest release and a couple of small bug fixes.
If you are on 1.0.x DO NOT UPGRADE, stay with 0.6.
It can be installed via:
grails install-plugin webtest

Saturday, January 31, 2009

Grails WebTest Plugin 0.6 Released

The latest version of the Webtest Plugin has been released for Grails 1.0.4. A release for 1.1 will follow shortly, with a newer WebTest snapshot which is now Java 5 dependent.

Release Notes

  • setUp/tearDown at the method and class level

    • classSetUp() and classTearDown() are run as individual test cases. SetUp() and tearDown() are run as the first and last steps of each test case.

  • Superclass changes in WebTest

    • The WebTest superclass now automatically runs all methods starting with test. This saves you having to manually maintain the suite method unless you really want to for test order reasons.

    • WebTest will also generate the test case name from the class and method name removing the need for repetitive webtest('blah'){...} code. The generated test name also makes it much easir to find the failing test from the generate reports.

    • MethodMissing code has been added so you can refactor a group of steps without having to wrap them in and ant.group closure.

    • You can now call config() as the first step in your test method to set WebTest options like host, port and ajax support

  • -nostart option allows you to runthe tests against a server that is already running. It should come after run-webtest on the command line

  • System parameters now passed through to WebTest. They need to be placed directly after grails on the command line e.g. grails -Dwt.headless=true run-webtest

    • -Dwt.headless=true to hide Swing monitor and stop browser launching

    • -Dserver.port=XXXX to get the tests to run against a server on a non-default port

  • The plugin has been updated with a recent snapshot version of WebTest which includes an update of HtmlUnit to version 2.3

  • Application lib folder now on WebTest classpath. This avoids the need to duplicate/move libraries into webtest/home/lib

  • Custom steps

    • You can now extend com.canoo.webtest.steps.Step by placing groovy classes in webtest/tests/step. They will be automatically loaded at runtime and allow for easy testing of complicated scenarios such as JSON interfaces and email integration

      • The last project I worked on used these custom steps to start, check then stop an embedded Wiser SMTP server for testing email functionality.

Upgrade Instructions

delete plugins/webtest-0.x

svn delete webtest/home, commit.

This avoids svn issues as the install script deletes the folder and extracts the latest build over the top, removing the .svn directories

grails install-plugin webtest

Friday, December 5, 2008

Spouse 2.0 - December 12

A great idea inspired by a colleague of mine (dpn) http://www.spouse2.com/

Sydney Groovy/Grails User Group

In between meeting all the interesting folk at OSDC, I attended the Sydney Groovy (and Grails) User Group. I presented a short talk on the new features in Grails 1.1 then demoed the Portlets Plugin and new features in the WebTest Plugin 0.6. Dave Peterson then gave a great Intro to Gant talk with comparisons to buildr. Come along next time to hear more from Dave about Gradle :) The group is organsied by Nick Carrol from Thoughtworks and the venue (in The Rocks near Sydney harbour) was great. If you're ever in the area, get onto the mailing list and see when the next meeting is.

Monday, November 10, 2008

Grails WebTest Plugin 0.6 alpha

I've been working on committing some improvements to the Grails WebTest Plugin. You can download the alpha version here (I haven't yet released it to the plugin repository). I'd appreciate feedback from users with existing applications with non-trivial webtests regarding any regressions or upgrade issues they have. If all looks ok I will update the official repository version shortly.

Release Notes

  • setUp/tearDown at the method and class level

    • classSetUp() and classTearDown() are run as individual test cases. SetUp() and tearDown() are run as the first and last steps of each test case.

  • New superclass AutoWebTest

    • This new superclass will automatically run all methods starting with test. This saves you having to manually maintain the suite method unless you really want to for test order reasons.

    • AutoWebTest will also generate the test case name from the class and method name removing the need for repetitive webtest('blah'){...} code. The generated test name also makes it much easir to find the failing test from the generate reports.

    • MethodMissing code has been added so you can refactor a group of steps without having to wrap them in and ant.group closure.

    • You can now call config() as the first step in your test method to set WebTest options like host, port and ajax support

  • -nostart option allows you to runthe tests against a server that is already running. It should come after run-webtest on the command line

  • System parameters now passed through to WebTest. They need to be placed directly after grails on the command line e.g. grails -Dwt.headless=true run-webtest

    • -Dwt.headless=true to hide Swing monitor and stop browser launching

    • -Dserver.port=XXXX to get the tests to run against a server on a non-default port

  • The plugin has been updated with the latest WebTest release which includes an update of HtmlUnit to version 2.3

  • Application lib folder now on WebTest classpath. This avoids the need to duplicate/move libraries into webtest/home/lib

  • Custom steps

    • You can now extend com.canoo.webtest.steps.Step by placing groovy classes in webtest/tests/step. They will be automatically loaded at runtime and allow for easy testing of complicated scenarios such as JSON interfaces and email integration

      • The last project I worked on used these custom steps to start, check then stop an embedded Wiser SMTP server for testing email functionality.

Upgrade Instructions

delete plugins/webtest-0.x

svn delete webtest/home, commit.

This avoids svn issues as the install script deletes the folder and extracts the latest build over the top, removing the .svn directories

grails install-plugin grails-webtest-0.6.zip

You need to copy the zip file into the root folder of your project and run the command there.