1

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;
}
Mike Stockdale
  • 5,256
  • 3
  • 29
  • 33
user85
  • 1,526
  • 5
  • 26
  • 42
  • What are you trying to achieve? Do you want to write a test that checks whether add returns the right result for various values of a and b? What test framework are you using Fit or Slim? – Fried Hoeben Nov 02 '14 at 08:46
  • yes, correct, i want to chk if add return correct rsults for diff values of a and b. I'm using Fit framework – user85 Nov 08 '14 at 09:31

4 Answers4

2

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

Fried Hoeben
  • 3,247
  • 16
  • 14
1

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

attaboy182
  • 2,039
  • 3
  • 22
  • 28
0

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
Manushin Igor
  • 3,398
  • 1
  • 26
  • 40
0

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