Previous page: SetUpFixture Next page: DoFixture Parent page: FitLibrary Fixtures
CalculateFixture
CalculateFixture is used to verify the result of one or more calculations for different combinations of input arguments. It does the same job as ColumnFixture in a different table format and with lot less code in the fixture class.Table Format
The first row of the table is the fixture class name. After that, the second row contains names for input parameters, followed by an empty cell, then followed by names of calculations (output values). All rows after that specify values for input parameters and expected outcomes for calculations. An empty cell is again used to separate inputs from expected outputs.
!|CalculateFixtureTest|
|firstPart|secondPart||together|
|Hello|World||Hello, World|
|Houston|We Have a Problem||Houston, We Have a Problem|
Fixture class
The fixture class should extend fitlibrary.CalculateFixture . It should declare one method for each calculation column. The method name must be equal to the calculation name concatenated with all parameter names (in this case togetherFirstPartSecondPart ). You can use CamelCase naming to separate words.Java Source Code
package info.fitnesse.fixturegallery;
import fitlibrary.CalculateFixture;
public class CalculateFixtureTest extends CalculateFixture{
public String togetherFirstPartSecondPart(String firstPart,String secondPart){
return firstPart+ ", "+secondPart;
}
}
.NET Source Code
using fitlibrary;
using System;
namespace info.fitnesse.fixturegallery
{
public class CalculateFixtureTest: CalculateFixture
{
public String TogetherFirstPartSecondPart(String firstPart,String secondPart)
{
return firstPart+ ", "+secondPart;
}
}
}
Python Source Code
from fitLib.CalculateFixture import CalculateFixture
class CalculateFixtureTest(CalculateFixture):
_typeDict = {}
# JAVA: String togetherFirstPartSecondPart(String firstPart,String secondPart){
_typeDict["togetherFirstPartSecondPart.types"] = ["String", "String", "String"]
def togetherFirstPartSecondPart(self, firstPart, secondPart):
return "%s, %s" % (firstPart, secondPart)
Notes
The method names can be very long and typing them manually is a bit error prone. Instead of that, just write the table, run the test and it will fail for the first time.Usage
Use the CalculateFixture to execute the same method or a set of methods for different combinations of input arguments and verify the results. If you just want to execute a method and the result is not important (or the method is void ), use the SetUpFixture instead (see SetUpFixture). If you want to execute methods on a domain object after initialising the properties, the ColumnFixture (see ColumnFixture) might be a better choice. The ColumnFixture will also allow you to just print the result of the calculation, not testing it. CalculateFixture treats an empty cell as a blank string, and compares it to the result, so it will fail the test if you leave an output cell empty.Previous page: SetUpFixture Next page: DoFixture Parent page: FitLibrary Fixtures
Add Child Page to CalculateFixture