user85
user85

Reputation: 1596

How to write fitnesse code for a method which accepts 2 parameters

I'm newbie to fitnesse and trying to run a simple calculator class which has "add" method accepting 2 parameters and returning the result. Can anyone help me to write the firnesse code for this, my method is as below

public int add(int a, int b) {
    return a+b;
}

Upvotes: 1

Views: 4766

Answers (4)

The correct answer is:

|script:<classPackage>.<ClassName>|
|check|add;|8|8|16|

First tell the script to navigate to the correct class. In the next line you have to call either a method or a constructor. You can call the method by it's name (or fancy smansy digibetic words that vaguely match) and tack on a semicolon. But anything put into the pipe-blocks after that will be interpreted as parameters for that method. So how do you put the expected output? The trick is to tell the FitNesse engine you need a result, with the keyword 'check'. This will make the final pipe-block be the field for the expected result, in this case 16.

Here is a picture of the java code

Here is a picture of the text input and the FitNesse sceen result

Upvotes: 0

Manushin Igor
Manushin Igor

Reputation: 3689

You can get the FitNesse tutorial there for .Net code. I tried to describe how to use FitNesse for different types of testing. If you want to check two parameters on the output you can do the following:

  • Return IEnumerable implementation with classes, which contains get and set properties (see here). NetRunner will use get properties if it can, otherwise it will use set properties. As a result, it will set all available data first and then compare items left.
  • You can use out parameters in the tests, so you can return several different values and check them

Upvotes: 0

Fried Hoeben
Fried Hoeben

Reputation: 3272

I believe you are trying to get a table like:

|AddFixtureTest |
|left|right|sum?|
|1   |1    |2   |
|2   |4    |6   |

This requires a java class like:

import fit.ColumnFixture;

public class AddFixtureTest extends ColumnFixture {
    public int left;
    public int right;

    public int sum(){
        return add(left, right);
    }
    private int add(int a, int b) {
        return a+b;
    }
}

See http://fitnesse.org/FitNesse.UserGuide.FixtureGallery.BasicFitFixtures.ColumnFixture

Upvotes: 2

attaboy182
attaboy182

Reputation: 2079

I assume Slim is fine by you and I'm gonna use script table for this (more out of habit):

|script| <class name> |
|add;| <variable1> | <variable2> |

As simple as that. And, make sure you are using the right libraries and pointing to the location of the where the class file is.

Example:

|import|
fitnesse.slim.test | 

If you are interested in knowing why I have placed a semi-colon after "add", and how script table works, please go through this:

http://www.fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.SliM.ScriptTable

Upvotes: 1

Related Questions