Is it possible to use multiple fitnesse fixture classes in one testtable (a scriptable i.e.) as in something like the following?
|script|FixtureClassOne,FixtureClassTwo|
|AMethodInFixtureClassOne|2|
|AMethodInFixtureClassTwo|2|
This is possible. You should load the fixture as a library. E.g.:
| import |
| my.fixtures.classpath |
| library |
| fixture 1 |
| another fixture |
| script |
| etc. |
No need to provide a fixture after the 'script' identifier anymore.
You do have to be aware that if the fixtures share non-unique method names you get into trouble
Objective: To have Multiple Fixtures associated with a single HTML Test Case
How: As you are working with fitnesses HTML Test case, you probably have at least a single fixture associated with it, which we will call default Fixture.
But in order to access another fixture (where control of execution passes to the other fixture), write a method in the default fixture class:
public Fixture run(String str) {
try {
Fixture fixture = Fixture.loadFixture(str);
return fixture;
} catch (Throwable e) {
// put your error handling here
e.printStackTrace();
}
return null;
}
From the Test case, pass the fully specified location with the project to the run() method. When the run() method returns the fixture to the HTML test case, it passes its execution via the new Fixture.
Related
I wrote a set of feature files for testing a custom framework and I want to allow testing of specific implementations of the interfaces of the framework. I want to run a whole lot of features with different implementations.
To do that, I have created a custom ObjectFactory and passing implementations using PicoContainer dependency injection. I added this factory to a cucumber.properties file and it works just fine. The only problem is - what if I have more than one set of implementations to test?
I can create several ObjectFactories, but how can I run the tests multiple times with different factories? Is it possible to pass ObjectFactory implementation to Runner class, using annotation or something alike? I run features with JUnit runner, and if I can have several of them with different factories, it should work, I think. However the only option to specify ObjectFactory I've found is cucumber.options file which is one for a module...
Currently it is not possible to use multiple object factories in Cucumber. As a work around you could implement a single object factory that delegates to a different object factory depending on some environment variable.
You may also want to consider using cucumber-spring instead of cucumber-pico as cucumber-spring can pick up springs context configuration annotations from step definitions. This can be done with minimal configuration if you structure your project like this:
| - runners
| | - CucumberConfigATest.java // #CucumberOptions(glue="steps", extraGlue="config.a")
| | - CucumberConfigBTest.java // #CucumberOptions(glue="steps", extraGlue="config.b")
| - steps
| | - SomeSteps.java
| | - MoreSteps.java
| - config
| | - a
| | | - StepsWithContextConfigA.java
| | - b
| | | - StepsWithContextConfigB.java
#mpkorstanje provided an answer I came up with as well. In case someone needs an example of implementation - here it is:
#RunWith(Cucumber.class)
#CucumberOptions(features="src/test/resources")
public class MyRunner {
#BeforeClass
public static void setup(){
System.setProperty(EventProcessorPicoFactory.EVENT_BUS_HANDLER, IUserECNDataHandler.class.getName());
}
}
public class MyFactory {
public MyObject build() {
String type = System.getProperty("my.property.name");
switch (type) {
case "my.value":
return new MyObject();
default:
throw new IllegalArgumentException("not implemented");
}
}
}
If i tried to run a givwenzen script using FitNesse SLIM getting error that givwenzen class is not picked up.
May be some class path error.
If anyone could help me with an example of givwenzen
Even with the addition of two numbers.
Thanks in advance
The project https://github.com/weswilliams/GivWenZen has a number of examples. Here's one:
1) Start with an example fixture actual class found in the givwenzen_test.jar.
2) In a FitNesse table it could look like this.
import and start should go in SetUp or SuiteSetUp
|import|
|org.givwenzen|
|script|
|start|giv wen zen for slim|
this is your test
|script|
| given| a ToDo item is due tomorrow |
| when | the date changes to tomorrow |
| then | a notification exists indicating the ToDo is due |
3) The following is an example step class and test step method ===
package bdd.steps;
#DomainSteps
public class ExampleSteps {
#DomainStep( “a ToDo item is due (.*)” )
public void createToDoWithDueDateOf(CustomDate date) {
// do something
}
#DomainStep( “the date changes to (.*)” )
public void theDateIs(CustomDate date) {
// do something
}
#DomainStep( “a notification exists indicating the ToDo is due” )
public boolean verifyNotificationExistsForDueToDo() {
// do something
return false;
}
}
I am using Rest Fixture with Fitnesse to make a GET request to url which returns non-xml response. Is there a way I could verify text/string (without xpath) in the content returned?
I found this solution.
TEXT is a supported content handler along XML and JSON. It is possible to override the content handler as TEXT and expect the content. Regular expression can also be used to expect content.
| Table:smartrics.rest.fitnesse.fixture.RestFixtureConfig | overridesContentHandlerConfig|
| restfixture.content.handlers.map | application/smil=TEXT |
!| Table:smartrics.rest.fitnesse.fixture.RestFixture | ${host} ||overridesContentHandlerConfig |
| GET | www.someurl.com | 200 | | [\s\w\d<>/=\:'.]*stringtoverify[\s\w\d<>/=\:'.]* |
You can use fit mode + NetRunner plugin (for .Net).
See here example, how to parse input line to the object.
Another way is to use Custom Comparators. This gives you more flexibility on customizing validation on custom/complicated results.
To use custom comparators:
documented here (search for 'CustomComparators')
required property: CustomComparators = <prefix:classname>[,<prefix:class name>]
motivation: The Slim protocol is all String values. It means that
comparison of an expected and actual result for complex datatypes is
limited to String equality or Regular Expression matching. If that is
not sufficient, a Custom Comparator can do more sophisticated
comparisons. Once registered, a Custom Comparator is triggered by its
prefix, followed by a colon, in front of the expected value.
Example Comparator implementation:
public class JSONAssertComparator implements CustomComparator {
#Override
public boolean matches(String actual, String expected) {
try {
JSONAssert.assertEquals(expected, actual, false);
return true;
} catch (JSONException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
Example plugins.properties:
CustomComparators = json:com.acme.JSONAssertComparator
Example ScriptTable usage:
|script|Customer |
|check|get|cust1|json:{id:cust1,name:"John Doe"}|
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;
}
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
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
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
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
Table example:
!script|SomeTest |
|Goto |$Url |
|check |IsAt|IndexPage|true|
|Index |CheckUserOrder? |
|0 |Name1 |
|1 |Name2 |
Code example:
public class SomeTest {
public string index;
public bool IsAt(string pageTitle){
//function for checking title of page
}
public string CheckUserOrder{
return username(index); // will get name of user for list which is other class
}
}
An exception is thrown: method name '0' not found in SomeTest...
I don't know why FitNesse is considering '0' as a method and not a parameter.
Are you working with the Slim test system? ColumnFixture requires the Fit test system. http://fitnesse.org/FitNesse.UserGuide.TestSystems
With Slim test system, use the DecisionTable http://fitnesse.org/FitNesse.UserGuide.SliM.DecisionTable
So your test will look like:
!|script|SomeTest|
|Goto|$Url|
|check|IsAt|IndexPage|true|
!|SomeTest|
|Index|CheckUserOrder?|
|0|Name1|
|1|Name2|
You are trying to combine a script and a decission table. If you are doing a script table, I expect you would have:
!|script|SomeTest|
|Goto|$Url|
|check|IsAt|IndexPage|true|
|check|CheckUserOrder|0|Name1|
|check|CheckUserOrder|1|Name2|