1

My requirement is to test or call a java method directly through fitnesse tool. I have used this tool for REST testing, but never for calling java methods directly. Also googled , but no solution. Any help would be appreciated.

Thanks

Vineet Singla
  • 1,609
  • 2
  • 20
  • 34

3 Answers3

0

You need to write 'fixture' code which connects FitNesse to your Java classes.

You'll find details here: http://fitnesse.org/FitNesse.UserGuide

For example, here's some information on one way to do that: http://fitnesse.org/FitNesse.UserGuide.FitLibraryUserGuide.DoFixture

Mike Stockdale
  • 5,256
  • 3
  • 29
  • 33
  • Thanks for the links, I wrote a fixture : !define TEST_RUNNER (fitlibrary.suite.FitLibraryServer) !path C:\Fitnesse_1\fitnesse.jar !path C:\Fitnesse_1\fitlibrary.jar !path C:\Fitnesse_1\com.jar !|com.fitnesse.HelloWorldFixture| |show|say hi| , but when i m running it , it shows Error: Could not find or load main class fitlibrary.suite.FitLibraryServer – Vineet Singla Jan 17 '14 at 00:50
  • Have you imported your fixture in your page? – Hrishikesh Jan 17 '14 at 06:08
0

I found the answer finally :

To call any method of any Java class, just use Generic Fixture Eg.

Java class :

package com.fitnesse.fixtures;


public class HelloWorld {

    public long getValue()
    {
        return 10;
    }

}

Fitnesse script to call the fore-mentioned java class :

!| Generic Fixture | com.fitnesse.fixtures.HelloWorld|
|myvar=getValue||10|

So first line calls the default constructor of the Java class, and
second line calls the method getValue and saves it in myvar and also validates it with 10.

teobais
  • 2,820
  • 1
  • 24
  • 36
Vineet Singla
  • 1,609
  • 2
  • 20
  • 34
0

Using a script table you can do something like this:

For static methods

|script   |java.util.UUID.randomUUID|
|$uuidVar=|to string                |
|check    |to string                | $uuidVar |

For non static methods

|script             | MyClass       |constructor   |arguments|here|
|$classToString=    | to string     |
|check              | to string     |$classToString|
|$classReference=   | get fixture   |
|$storeMethodOutput=| my method name|

Any of the $ variables defined can be reference in later tables for just about whatever you need.

Jason Slobotski
  • 1,386
  • 14
  • 18