Monday, July 27, 2009

Simple FitNesse example with CSlim

Tinkering with the FitNesse acceptance testing system, I cloned the CSlim repo, but its README was short on detail about getting the thing to talk to FitNesse.

Attempting to build (on Ubuntu karmic) out of the box failed:

$ make
compiling ListExecutor.c
compiling SlimConnectionHandler.c
compiling SlimList.c
compiling SlimListDeserializer.c
compiling SlimListSerializer.c
compiling SlimUtil.c
compiling StatementExecutor.c
compiling SymbolTable.c
compiling SocketServer.c
compiling TcpComLink.c
Building archive lib/libCSlim.a
ar: lib/libCSlim.a: No such file or directory
make: *** [lib/libCSlim.a] Error 1
The workaround is straightforward: mkdir lib followed by make.

So now what?

$ ./CSlim_server --help
getaddrinfo: Servname not supported for ai_socktype
Following the recommendation in the SLiM docs, I created a page called CslimTest (by editing FrontPage to contain a new line with CslimTest) that contained merely
!define TEST_SYSTEM {slim}
After I clicked the Test button, the page cleared, paused for a few seconds, and then gave a red box with "Testing was interupted and results are incomplete." Clicking Output Captured, I saw a stacktrace that ended with java.lang.ClassNotFoundException: fitnesse.slim.SlimService.

Maybe I could crib from the docs for another server. The FitNesse download page points to servers for various languages, and from there I arrived at a Getting Started page for fitSharp, a C# server for FitNesse, which had the following config:

!define TEST_SYSTEM {slim}
!path c:\myfolder\mytest.dll
!define COMMAND_PATTERN {%m -r fitSharp.Slim.Service.Runner,c:\program files\fitsharp\fitsharp.dll %p}
!define TEST_RUNNER {c:\program files\fitsharp\Runner.exe}
So next I try
!define TEST_SYSTEM {slim}
!define TEST_RUNNER {/home/gbacon/src/cslim/CSlim_server}
I got a similar failure, but this time the class that failed to load was .home.gbacon.src.cslim.CSlim_server.

Even though the fitSharp used !path for test assemblies, Drew suggested pointing it to CSlim_server as in

!define TEST_SYSTEM {slim}
!path /home/gbacon/src/cslim/CSlim_server
But the test still died with ClassNotFoundException.

I monkeyed more with COMMAND_PATTERN, and finally got a quick error using

!define TEST_SYSTEM {slim}
!path /home/gbacon/src/cslim/CSlim_server
!define COMMAND_PATTERN {%m %p}
Instead of Output Captured, I see Tests Executed OK. I notice in src/Main/DecisionTableExample.c there's a Division fixture that seems to match the example in the two-minute example, so I copy-and-paste to get
!define TEST_SYSTEM {slim}
!path /home/gbacon/src/cslim/CSlim_server
!define COMMAND_PATTERN {%m %p}

|eg.Division|
|setNumerator|setDenominator|Quotient?|
|10          |2             |5        |
|12.6        |3             |4.2      |
|100         |4             |33       |
Red box still, and the tests aren't running. Not much help in the output log, but FitNesse complained: "Cannot run program "fitnesse.slim.SlimService".

Remove %m from COMMAND_PATTERN. Progress! Nothing's running, but I see a bunch of exceptions and text with yellow backgrounds, such as "eg.Division Could not find class eg.Division." Maybe it doesn't like the leading eg.

!define TEST_SYSTEM {slim}
!path /home/gbacon/src/cslim/CSlim_server
!define COMMAND_PATTERN {%p}

|Division|
|setNumerator|setDenominator|Quotient?|
|10          |2             |5        |
|12.6        |3             |4.2      |
|100         |4             |33       |
Now Division goes green, but it doesn't like the input methods ("Method setSetNumerator[1] not found in Division." for example). The method names in the fixture are setNumerator, setDenominator, and Quotient, so mangling must be happening somewhere.

That's what I get for trying to think ahead of it:

!define TEST_SYSTEM {slim}
!define COMMAND_PATTERN {%p}
!path /home/gbacon/src/cslim/CSlim_server

|Division|
|numerator|denominator|Quotient?|
|10       |2          |5        |
|12.6     |3          |4.2      |
|100      |4          |33       |
Now the first two rows pass, and the third fails as expected.

2 comments:

Doug said...

Glad you got it working. Here is my test setup just for reference.

!define TEST_SYSTEM {slim}
!define TEST_RUNNER {/Users/dougbradbury/Projects/CSlim/CSlim_server}
!define COMMAND_PATTERN {%m}

I'll add a lib directory to the git repo.

Here are a couple of other fixture examples that are in the test fixture:

|Multiplication|
|Multiplicand1|Multiplicand2|Product?|
|1|1|1|
|5|4|20|

!|Query: EmployeePayRecordsRow|
|id|pay|
|1|1000|

!|script|Count|
|count|
|count|
|check|counter|2|

Unknown said...

Any way to get this working on windows yet? I have been trying and there have been some problems with Win32SocketServer.c


Thanks. :)