Friday, September 11, 2009

FitNesse ActionFixture

After a few minutes of looking for code that demonstrates what an fit.ActionFixture does I decided I would see if FitNesse's error messages were sufficient for me to know what to do next.

The table comes directly from the FitNesse book. I quickly understood that I would need a BuyActions Java class after running the test with only the table in place. Creating the class with the fields total and price lead to further understanding and I quickly had the class I needed to pass the tests.
!|fit.ActionFixture |
| start | !-BuyActions-! |
|check|total|0.00|
|enter|price|12.00|
|press | buy |
|check|total|12.00|
|enter|price|100.00|
|press | buy |
|check|total|112.00|


import fit.ActionFixture;
 
public class BuyActions extends ActionFixture {
 public double price, total;
 
 public double total() {
  return total;
 }
 
 public void buy() {
  total += price;
 }
 
 public void price(double price) {
  this.price = price;
 }
 
}