Friday, January 02, 2009

Fitnesse ArrayFixture: my simple example

Recently I've been fighting with Fitnesse, specifically a pyFit server, trying to get an ArrayFixture to run properly. The only example of ArrayFixture I could find was the generic one. Here is a better example of ArrayFixture.

I'm calling this from within a DoFixture, mind you, so sorry if there's that added complication, but you should be able to figure out what's happening based on this.


class LwRow(object):

_typeDict = {}

def __init__(self):
self.rowNumber = None ; self._typeDict['rowNumber' ] = "Int"
self.indent = None ; self._typeDict['indent' ] = "Int"
self.refobjType = None ; self._typeDict['refobjType'] = "String"
self.refobjId = None ; self._typeDict['refobjId' ] = "Int"
self.sNumber = None ; self._typeDict['sNumber' ] = "String"
# ... blah more here...

def name(self):
self._typeDict['name'] = "String"
return self.linkOrgEditContractorText or ''

def getSetOfRowObjects(self):
rows = []
obj = LwRow()
obj.rowNumber = 1
obj.indent = 3
# ... more setting here...
rows.append(obj)
# blah, repeat, appending more rows...
return rows

class ReviewLwsArrayFixture(ArrayFixture):

def __init__(self, p, c, dr, user, trans=None):
ArrayFixture.__init__(self)
rows = []
#... do stuff here to retrieve data...
retData = getSetOfRowObjects()
print "Have retData=%s" % (pformat(retData))

# THESE ARE PRO-FORMA, MUST BE HERE:
self.paramCollection = retData
self.setActualCollection()

def getTargetClass(self):
return LwRow

def reviewLwsArrayAsUserPpCcDrUser(self, p, c, dr, user, trans):
return self.ReviewLwsArrayFixture(p=p, c=c, dr=dr, user=user, trans=trans)


# then you can write your UAT / Fitnesse code as follows.
# Note that I can use ANY attribute of the lwRow object without declaring it
# in my arrayfixture code (I have LwRow declared in a non-fixture related module)

|review lws array as user | gcUser| pp | p1 | cc | c1 | dr| Dr1 |
|rowNumber|name|indent|refobj type|
|1|manual name one|Manual|False|
|2|subMc1|LW Sub|True|
|3|subMc2|LW Sub|True|
|4|subMc3|LW Sub|True|


and / or:

|review lws array as user | gcUser| pp | p1 | cc | c1 | dr| Dr1 |
|rowNumber|name|sNumber|
|1|x|62|
|2|y|63|
|3|z|64|
|4|z|46|
|5|z|55|
|6|z|63|
|7|q|64|

That's it!

No comments: