How to explicitly fail a FIT test from a DoFixture
Back when I was at DataCert, my buddy Jeff Palermo wrote a blog post on this topic. Since then, I have switched languages from C# to Java, so here is the same thing, translated to Java.
import fit.Fixture; import fit.Parse; import fitlibrary.DoFixture; public class MyDoFixture extends DoFixture { private Parse currentParse; public void RunSystem() { //hook into system } public void MakeSureFileWasSaved() { //hook into system to make sure file was saved. if it wasn't. .. wrong(currentParse, "File wasn't saved."); } @Override protected Object interpretCells(Parse cells, Fixture fixture) { currentParse = cells; return super.interpretCells(cells, fixture); } }
The key thing being to override interpretCells() rather than MethodCells().
Note that this will mark the first cell of the current row as wrong. If you want to mark a different cell wrong (say the 3rd cell, for example) you would do this:
public void MakeSureFileWasSaved() { //hook into system to make sure file was saved. if it wasn't. .. wrong(currentParse.more.more, "File wasn't saved."); }
The other cool trick that I am using in my current project is to use the abandonStorytest() method, which also requires the currentParse.
I am using FitNesse to do integration testing and it connects to a database. One thing it does it clean up all the 'test' data. To ensure that the tests don't accidentally delete data in a database that isn't a 'development' database, there is a check in the FitNesse page that checks for non-developer databases and stops the test cold (i.e., it never gets to the "clean up all our test data" cell of the table).