(Quick Reference)

2 Getting started - Reference Documentation

Authors: Erik Pragt (jWorks.nl), Marcin Erdmann, John Engelman

Version: 2.0.3

2 Getting started

You can install the plugin by typing
$ grails install-plugin fitnesse

Now, whenever you start up your Grails application (using run-app for example), a Fitnesse server will also start internally, allowing the Fitnesse Wiki to connect to the Grails application.

Note that currently you'll need to start up and close your Grails application yourself; the plugin doesn't do this for you. This might change in the future, but for now, it's a manual step.

The internal Fitnesse server allows connections made by the Fitnesse Wiki to be interpreted by Fixtures, which run against your application.

2.1 Quickstart

For the impatient, this is the quickstart to get Fitnesse to work with Grails.

Step 1: Create a new Grails application

grails create-app myapp
cd myapp

Step 2: Install the Fitnesse Plugin

grails install-plugin fitnesse

Step 3: Start the Grails application

grails run-app

Step 4 (in a differtent console or terminal): Start Fitnesse

grails run-fitnesse

Step 5: Configure Fitnesse (for Linux/MacOS)

Browse to http://localhost:9090, and replace (See 'Edit' in the left side menu) the contents of the page with the following:

!define TEST_SYSTEM {slim}
!define COMMAND_PATTERN {echo}

|import | |nl.jworks.fitnesse.quickstart|

|echo| |input|output?| |hello| hello| |world| world|

The COMMAND_PATTERN needs to be configured to point to an executable to prevent Fitnesse from starting a server. On Windows, for example, this can be an empty batch file: !define COMMAND_PATTERN {c:/myemptybat.bat}.

Save the page.

Step 6: Verify it works

Click on Properties, select Test under 'Page type', click on Save properties to save the page.

Now press Test. Everything should be Green now!

2.2 Fixtures

Fitnesse Fixtures, not to be confused with Grails Fixtures, allow a bridge between the Fitnesse Wiki and the System Under Test (SUT).

Fixtures are similar to Grails artifacts and share most of their characteristics, like hot reloading and Dependency Injection. All Fixtures should be created in the 'Fitnesse' directory in the grails-app directory.

Example

Below you'll find an example Wiki test plus the Fixture which will serve as the bridge between the Wiki and the SUT.

Wiki:

|loan calculator       |
|income|debts|category?|
|10000 |500  |A        |
|5000  |10000|C        |

And the Fixture:

class LoanCalculatorFixture {
    // Input parameters
    int income
    int debts

// Output parameter String category

// Dependency Injected def loanCalculationService

void execute() { this.category = loanCalculationService.calculateLoanCategory(income, debts) } }

Explanation

The Wiki Tests consists of 3 parts:

  • the fixture name (loan calculator)
  • the header(income, debts, and category)
  • and the body (the rest of the table). As you can see, category is suffixed with a question mark to indicate this is not a value to be set, but rather to be read ('get'). As such, first the input values are set, then the execute method is called by Fitnesse, and finally the output are called, in this case category.

A small note: normally output parameters are 'functions' and not getters. This means you would need an extra method for the output parameters. In the Grails version of the Fitnesse runner, this isn't necessary (fortunately!), and Fitnesse will check both the 'functions' as well as the Groovy properties. Less code to write, less code to maintain!

2.3 Wiki

The Wiki contains all the tests. The wiki consists of two parts:
  • Formatted text
  • Tables

Tables are the tests, and only tables are executed.

The following tests are at least supported by the Grails Fitnesse plugin:

NameDescription
Decision TableSupplies the inputs and outputs for decisions. This is similar to the Fit Column Fixture
Query TableSupplies the expected results of a query. This is similar to the Fit Row Fixture
Script TableA series of actions and checks. Similar to Do Fixture.
ImportAdd a path to the fixture search path.

The following tables might work, but at the moment, they haven't been tested yet. They are included here for completeness.

NameDescription
Table TableWhatever you want it to be!
Subset Query TableSupplies a subset of the expected results of a query.
Ordered query TableSupplies the expected results of a query. The rows are expected to be in order. This is similar to the Fit Row Fixture
CommentA table that does nothing.
Scenario TableA table that can be called from other tables.
Library TableA table that installs fixtures available for all test pages

For more information, please check out the Fitnesse Slim documentation on Test Tables.

2.4 Testrunner

The Fitnesse Plugin can be used when testing your application from the command line by using the bundled testrunner. The testrunner can be launced by typing:

grails test-app integration:fitnesse <name of suite or test>

An example of this can be found below:

grails test-app integration:fitnesse "FrontPage.GrailsTestSuite.SlimTestSystem?suite"

It is also possbible to run multiple tests or suites. This can done by appending the suite or tests names:

grails test-app integration:fitnesse "FrontPage.GrailsTestSuite.FirstSuite?suite" "FrontPage.GrailsTestSuite.SecondSuite?suite"

Running these commands will start up the Grails application, launch the Fitnesse tests, and return the results in a standard Grails test report.

Run sequence

The default Wiki Suite or Test which will be run using grails test-app will be determined in the following way:

  1. First, if a suite or test is specified as an argument to grails test-app, the argument will be used
  2. Second, if a suite or test is specified in the Config.groovy, that one will be used
  3. Thirdly, all tests defined on the Fitnesse Frontpage (FrontPage?suite) will be run if none of the above options are applicable