Skip to content

Cory Foy

Organizational agility through intersecting business and technology

Menu
  • FASTER Fridays
  • Mapping Mondays
  • Player Embed
  • Search Videos
  • User Dashboard
  • User Videos
  • Video Category
  • Video Form
  • Video Tag
Menu

Using Symbols in Java Fitnesse Fixtures

Posted on March 28, 2006 by Cory Foy

Fitnesse has a nifty feature where you can store the output of one test table in a symbol that you can then use in a subsequent table. The documentation does a good job explaining the concepts, but seems to be missing some code behind the scenes to make it work. So I’ve put together a simple example of using it.

One thing to note is that this feature is implemented in the various version differently, which is why this is targetted at the Java Fitnesse version.

Let’s say we have one class that returns a value (SymbolTextFixture) we need to use in a subsequent test (SymbolTestRecall). First, let’s look at our value provider:

import fit.ColumnFixture;

public class SymbolTestFixture extends ColumnFixture {
  public SymbolTestFixture() {
    super();
  }

  public String getTestValue() {
    return "Set from Fixture!";
  }
}

So, we have a class whose instance provides us some value. Now, we have a class that needs to take in this value so it can display it:

import fit.ColumnFixture;

public class SymbolTestRecall extends ColumnFixture {
  public String testValue = "Not Set";

  public SymbolTestRecall() {
    super();
  }

  public String getTestValue() {
    return testValue;
  }
}

So, obviously our goal is to get the test value from a SymbolTestFixture instance into the testValue field of SymbolTestRecall, so it’s getTestValue() method can display it.

As mentioned above, there is a special header syntax within ColumnFixtures that let you save the output from a method into a symbol, which can be reused later. Here’s the Fitnesse fixture we’d use for this:

|Symbol Test Fixture|
|=getTestValue?|
|myKey|

The above test is saying to use a class called SymbolTestFixture to store the output of the getTestValue method into the symbol myKey. How does it know to do that? The = in front signals to store the value, and the ? at the end tells the Fit runner that the value will be coming from a method.

So now that we have the value in myKey we want to use it. This test shows that:

|Symbol Test Recall|
|test Value=|getTestValue?|
|myKey|Set from Fixture!|

This test says to use an instance of the SymbolTestRecall class and set the testValue field with the value stored in the symbol myKey. It then verifies that the value returned from the getTestValue method is the value returned from our previous test (“Set from Fixture!”).

And there you have it! The complete Fitnesse test looks like:

!path /home/foyc/workspace/fit_stuff/bin

|Symbol Test Fixture|
|=getTestValue?|
|myKey|

|Symbol Test Recall|
|test Value=|getTestValue?|
|myKey|Set from Fixture!|

The above just adds the !path directive to where the output of my classes are. Build your classes, fire up your Fitnesse server, and test to green goodness!

5 thoughts on “Using Symbols in Java Fitnesse Fixtures”

  1. Luke Melia says:
    March 28, 2006 at 11:52 pm

    Cool. Any idea if this works with the .NET Fit server?

  2. Cory Foy says:
    March 29, 2006 at 8:19 am

    Hi Luke,

    I believe that Symbols are supported by the Java, .NET, and Python versions. As I mentioned they are implemented differently – I’ll see if I can get a .NET version up soon.

  3. Shameem says:
    April 11, 2006 at 10:42 pm

    Hi, That was helpful.. I am trying to do the same on Row Fixture.

    I need the output of a query saved to a variable and need to use that in another input table. Any Suggestions..

    I need actcode to be a variable which gets the output of my first query.

    !|Select|select ACTIVATION_CODE from account where LOGIN=’${usernameText}’|
    |=ACTIVATION_CODE|
    |actcode|

    !|Select|select ACCOUNT_ID from account where ACTIVATION_CODE=${actcode}|
    |ACCOUNT_ID|
    |4210|

  4. Cory Foy says:
    April 12, 2006 at 7:17 am

    Hi Shameem,

    Unfortunately symbols and variables aren’t the same thing. You could take the symbol and pass it into your custom fixture class using the same concepts as the above article which could then do your query for you.

    Also, you might want to try posting your question to the Fitnesse group http://groups.yahoo.com/group/fitnesse.

  5. Anonymous says:
    October 18, 2007 at 3:20 am

    Nice. Do you know or have any idea of how to make this work with/in ActionFixtures?

    Cheers,
    Johan

Comments are closed.

© 2025 Cory Foy | Powered by Superbs Personal Blog theme