Jeffrey Palermo (.com)

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
How to explicitly fail a FIT test while using the new DoFixture - level 300
The FitLibrary has been recently ported to .Net, and I love using the DoFixture.  One problem is that the normal DoRow and DoCell methods of the Fixture class don't run in the DoFixture.  With other fixtures, I'm used to hooking into to these places in order to spread logic throughout my FIT test.  DoFixture uses two new methods: 
System.Collections.IEnumerable ParameterCells(CellRange theCells)
and
System.Collections.IEnumerable MethodCells(CellRange theCells)

This is how the DoFixture implements it's special behavior.  For example:
|MyDoFixture|
|Run System|
|Make Sure File|taxes.txt|Was Saved|


This is a simple fixture that makes sure the system saves a file "taxes.txt".  Here, I'm not using the built-in Check method.  I'm implementing one myself.  Either the file was saved or it wasn't.

My underlying fixture will look like this:

using fit;

using fit.exception;

 

public class MyDoFixture : DoFixture

{

    public MyDoFixture()

    {

    }

 

    public void RunSystem()

    {

        //hook into system

    }

 

    public void MakeSureFileWasSaved()

    {

        //hook into system to make sure file was save.  if it wasn't. ..

        throw new fit.exception.FitFailureException("File should have been saved.")

    }

}


This works, but will throw an exception instead of failing the test.  I need to register a FIT failure and not an exception.  FIT treats these two differently.  In order to fail a FIT test, I have to use the Wrong(Parse theParse) method.  I have to have the current Parse object in order to call this method.  The Parse object is the current cell/row/table.  The FIT table is composed of a Parse hierarchy.  I don't really like the way it's set up, but that's not the point of this post.

In order to call the Wrong(...) method to fail the test correctly with a reason to output to the screen, I must obtain the current Parse object.  Because the DoFixture doesn't fire the virtual DoCell or DoRow method, I can't use these.  Instead, I'll override a DoFixture method that fires for every row and modify my fixture like this:

using fit;

using fit.exception;

 

public class MyDoFixture : DoFixture

{

    private Parse _currentParse;

 

    public MyDoFixture()

    {

    }

 

    public void RunSystem()

    {

        //hook into system

    }

 

    public void MakeSureFileWasSaved()

    {

        //hook into system to make sure file was save.  if it wasn't. ..

        this.Wrong(_currentParse, "File wasn't saved.");

    }

 

    protected override System.Collections.IEnumerable MethodCells(CellRange theCells)

    {

        _currentParse = theCells.Cells;

        return base.MethodCells(theCells);

    }

}


With this code, I have my fixture maintain the current Parse (I'm tracking the current row) so that when a line fails, I can properly fail the test with an appropriate message.  This is a much better solution that throwing an exception.  Throwing an exception means that the test environment blew up and needs to be fixed.  Test failures mean the code broke.  An exceptioin means the FitNesse server broke..

Posted 02-23-2006 3:08 PM by Jeffrey Palermo
Filed under:

[Advertisement]

Comments

Liang wrote re: How to explicitly fail a FIT test while using the new DoFixture - level 300
on 02-23-2006 10:38 PM
Jeffrey,

It looks very interesting to me. Could you post a source project to help us catch up?

Thanks!
Jason Haley wrote Interesting Finds
on 02-24-2006 8:45 AM
Steve Donie wrote re: How to explicitly fail a FIT test while using the new DoFixture - level 300
on 11-28-2007 2:18 PM

To do this in a Java-based DoFixture, the code looks like this:

<code>

 @Override

 protected Object interpretCells(Parse cells, Fixture fixture) {

   currentCell = cells;

   return super.interpretCells(cells, fixture);

 }

</code>

Kenneth Kasajian wrote re: How to explicitly fail a FIT test while using the new DoFixture - level 300
on 12-12-2007 3:18 AM

“PhraseFixture” -- a better DoFixture()

The Case for “PhraseFixture” -- a better DoFixture() for use with FIT and FitNesse Acceptance Testing Framework.

The powerful DoFixture() in FitLibrary simulates English like specification. The PhraseFixture proposal takes this to the next level.

Please see article here:

codeproject.com/.../PhraseFixture.aspx

I'd like to get some feedback.

Kenneth Kasajian wrote re: How to explicitly fail a FIT test while using the new DoFixture - level 300
on 12-12-2007 8:49 PM

Proposing something called “PhraseFixture” -- a better DoFixture() for use with FIT and FitNesse Acceptance Testing Framework.

The powerful DoFixture() in FitLibrary simulates English like specification. The PhraseFixture proposal takes this to the next level.

Please see article here:

codeproject.com/.../PhraseFixture.aspx

I'd like to get some feedback.