Search code examples
javafitnesse

Sharing content.txt data between multiple Fitnesse tests


I'm trying to use one content.txt file between two Fixture tests. An intermediate class, TestUtility, gets the data from a content.txt file, and Two fixture tests call that utility class. However, I'm getting a NullPointerException from getText. I think Fitnesse doesn't accept an intermediate test file. Does anyone know how I could make this work?

public class TestUtility  extends TableFixture { 
       @BeforeClass
        public void setup()  {
            System.out.println("in setup");
            cellR0C0 = getText(0,0);
            cellR1C0 = getText(1,0);
            cellR2C0 = getText(2,0);
            cellR0C1 = new Double(getInt(0,1));
            cellR1C1 = new Double(getInt(1,1));
           cellR2C1 = new Double(getInt(2,1));

    /**
     *
     * @param fitnessRows
     */
    public void showResults(int fitnessRows){

    }
}//end class TestUtility  

public class MyTestFixture {
        /**
         *
         * @param fitnessRows
         */
         public void showResults(int fitnessRows){
            TestUtility testUtility = new TestUtility()
            testUtility.setUp();
            testUTility.restOfTest()
        }
   }

content.txt
#!|TestUtility|
!|fitnesse.fixtures.TestUtility|
|ABCDE101|200|
|ABCDE102|300|
|ABCDE103|400|

Solution

  • When a fixture like TestUtility is created by the FitNesse test engine, it is initialized by FitNesse to let you access information from the test page with methods like getText. When you create a fixture with new, this information is not initialized and calling getText will fail, as you saw.

    If you want to use information from a fixture in another class, you can put the information into static fields so you can then use it in another class without creating a new instance with new.