What is fit ?

fit is WardCunningham's Framework for Interactive Tests. It reads user test specifications (input data, expected results) in HTML tables; executes some user test code; and colour-codes the HTML output accordingly. Zwiki can apply fit to tables within a page. Here's how it looks. The last column's cells should be green and red.

numerator denominator quotient()
6 3.0 2.0
10 3.0 3

For more examples, see RSTTests and http://fit.zwiki.org/FitExamples .

SimonMichael did the python port and added support for it in ZWiki. There are ports for the other major languages.

fit's home site
more about python fit
UnixReview?: Regular Expressions, Fit makes for good tests

How fit works

  • fit reads HTML tables which are simple test specifications. Each table names a fixture class in it's first cell, and contains method names, attribute names, and test data in the others
  • The fixture class is based on one of fit's base Fixture classes, with your own test code added. Eg ColumnFixture, RowFixture, ActionFixture; each interprets the table data in a particular way.
  • The class is instantiated; methods and attributes are called, set and checked according to the Fixture class's semantics
  • cells are coloured and marked up depending on the results. Scroll down to see more examples.

Zwiki's fit support

A wiki is a convenient place to browse, develop, and run fit tests. Zwiki has support for fit built in and enabled by default. On each page view, any HTML, StructuredText or RestructuredText tables containing fit tests are parsed, run and coloured. Note, the CVS python fit version used here processes only tables which contain fit. or fixtures. in their first cell, to co-exist with non-fit tables and help with security. The fixture class is assumed to be somewhere in Zope's PYTHONPATH or in the ZWiki product directory. There may be security & performance issues for public sites.

Most pages on this wiki use StructuredText formatting. You need to be clever to avoid structured text or wiki formatting interfering with your tests. Eg put a ! before a wiki-named class name in the first cell. StructuredTextTables may work, but STX tends to mess up numbers by turning them into bullets.

RestructuredText formatting may work well for fit. HTML isn't allowed on these pages, but RestructuredText tables look promising (there's an example on RSTTests).

How to install fit for Zwiki

Here's the best way to get fit working with Zwiki:

  1. you might need python 2.3
  2. preferably, run the latest zwiki ; it reports problems better
  3. check out the latest python fit into your ZWiki plugins directory (darcs get http://zwiki.org/repos/fit)
  4. restart zope
  5. copy this page's text to a StructuredText page on your wiki and see if the tables are coloured.


doesn't work? --Bill Page, Mon, 14 Aug 2006 19:16:24 -0700 reply
I guess this fit stuff isn't working any more on this site?

On my system I have a stx page contain the words " ... as you set fit." which triggers the error:

       Traceback (most recent call last):
         File "/var/zope/Products/ZWiki/plugins/Fit.py", line 29,
         in ? from fit.Parse import Parse
      ImportError: No module named fit.Parse

stx says:

  if page.hasFitTests(): t = page.runFitTestsIn(t)

And plugins/Fit.py says:

  def hasFitTests(self):
    Does this page have any tables containing fit tests ?

    Should match python fit's regexp.
    return re.search(r'([Ff]ixtures|\bfit)\.',self.read()
                     ) is not None


All this looks kind of cludgey to me and probably doesn't work this way any more... One more reason to upgrade?

... -- Thu, 31 Aug 2006 14:22:46 -0700 reply
I ended a sentence with "fit." and I got the same traceback as Bill. ZWiki version: 0-37-0.