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
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 thegrails-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 |
class LoanCalculatorFixture { // Input parameters int income int debts // Output parameter String category // Dependency Injected def loanCalculationService void execute() { this.category = loanCalculationService.calculateLoanCategory(income, debts) } }
- 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
Name | Description |
---|---|
Decision Table | Supplies the inputs and outputs for decisions. This is similar to the Fit Column Fixture |
Query Table | Supplies the expected results of a query. This is similar to the Fit Row Fixture |
Script Table | A series of actions and checks. Similar to Do Fixture. |
Import | Add a path to the fixture search path. |
Name | Description |
---|---|
Table Table | Whatever you want it to be! |
Subset Query Table | Supplies a subset of the expected results of a query. |
Ordered query Table | Supplies the expected results of a query. The rows are expected to be in order. This is similar to the Fit Row Fixture |
Comment | A table that does nothing. |
Scenario Table | A table that can be called from other tables. |
Library Table | A table that installs fixtures available for all test pages |
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>
grails test-app integration:fitnesse "FrontPage.GrailsTestSuite.SlimTestSystem?suite"
grails test-app integration:fitnesse "FrontPage.GrailsTestSuite.FirstSuite?suite" "FrontPage.GrailsTestSuite.SecondSuite?suite"
Run sequence
The default Wiki Suite or Test which will be run usinggrails test-app
will be determined in the following way:
- First, if a suite or test is specified as an argument to
grails test-app
, the argument will be used - Second, if a suite or test is specified in the Config.groovy, that one will be used
- Thirdly, all tests defined on the Fitnesse Frontpage (FrontPage?suite) will be run if none of the above options are applicable