Search code examples
testingfitnesse

FitNesse dynamic fixture for test table?


Is it possible to have a dynamic fixture for a given FitNesse table? Here is a simple example table:

|SetUpRequestFixture                 |
|base element|xml-request            |
|key         |test123                |

Is it possible to write a method inside the Fixture class for setting up any number of child arguments? I would like to be able to extract the key/value pairs in any number of FitNesse tables to be able to build a XML string from them. Something like this:

public class SetUpRequestFixture {
  public void setUp(String... arguments) {

  }
}

I've been looking at http://fitnesse.org/FitNesse.UserGuide.FixtureGallery.FitLibraryFixtures.SetUpFixture but it looks like it needs the name of every element in the method header. Also, this would not work because it removes the name/value association created with the parameters.

Could I define my own fixture that overrides the default parsing behavior? It could be a valuable addition to the next version of Fitnesse.


Solution

  • Yes you can. A fixture can get access to the structure of the table and do anything it wants to. In classic Fit, you override the doRows method:

    public class MyFixture extends Fixture {
        public void doRows(Parse rows) {
            ... use methods on rows to iterate through the table
        }
    }
    

    Take a look at the fitlibrary source code for some good examples of how this works. (There may be some newer method to do this in fitlibrary - I'm not up to date on what the author has been doing.)