1

I just installed the fitnesse-launcher-maven-plugin from uk.co.javahelp.fitnesse and I can see it runs fine.

Now I'd like to write some tests and have them seen and executed during the build.

My pom.xml file contains the following plugin:

  <profiles>
    <profile>
      <id>wiki</id>
      <build>
        <plugins>
          <plugin>
            <groupId>uk.co.javahelp.fitnesse</groupId>
            <artifactId>fitnesse-launcher-maven-plugin</artifactId>
            <version>1.4.2</version>
            <executions>
              <execution>
                <goals>
                  <goal>set-up</goal>
                  <goal>wiki</goal>
                  <goal>tear-down</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>auto</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>uk.co.javahelp.fitnesse</groupId>
            <artifactId>fitnesse-launcher-maven-plugin</artifactId>
            <configuration>
              <failIfNoTests>false</failIfNoTests>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>set-up</goal>
                  <goal>run-tests</goal>
                  <goal>tear-down</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

Following the plugin website documentation at

http://fitnesse-launcher-maven-plugin.googlecode.com

I have also created the following directories and empty (for now) files:

stephane@stephane-ThinkPad-X301:toolbox> tree src/test/java/fitnesse/
src/test/java/fitnesse/
├── FirstTestSuite
│   ├── content.txt
│   ├── NestedSuite
│   │   ├── AnIndividualTest
│   │   │   ├── content.txt
│   │   │   └── properties.xml
│   │   ├── content.txt
│   │   └── properties.xml
│   ├── properties.xml
│   └── Setup
│       ├── content.txt
│       └── properties.xml
└── plugins.properties

If running the command:

mvn verify -P wiki

then I can see at

http://localhost:9123/

some default Fitnesse tests which are not mine.

On the other hand, if I execute the command:

mvn verify

then there are no tests to be executed:

[INFO] Executed tasks
[INFO] 
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:run-tests (default) @ toolbox ---
[INFO] ------------------------------------------------------------------------
[INFO] Setting FitNesse variable [maven.classpath] to [
!path /home/stephane/dev/java/projects/toolbox/target/test-classes
!path /home/stephane/dev/java/projects/toolbox/target/classes
!path /home/stephane/.m2/repository/org/fitnesse/fitnesse/20140201/fitnesse-20140201.jar
!path /home/stephane/.m2/repository/org/htmlparser/htmlparser/2.1/htmlparser-2.1.jar
!path /home/stephane/.m2/repository/org/htmlparser/htmllexer/2.1/htmllexer-2.1.jar
!path /home/stephane/.m2/repository/org/apache/velocity/velocity/1.7/velocity-1.7.jar
!path /home/stephane/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
!path /home/stephane/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar
!path /home/stephane/.m2/repository/org/json/json/20090211/json-20090211.jar
!path /home/stephane/.m2/repository/com/googlecode/java-diff-utils/diffutils/1.2.1/diffutils-1.2.1.jar
!path /home/stephane/.m2/repository/org/eclipse/jgit/org.eclipse.jgit/2.3.1.201302201838-r/org.eclipse.jgit-2.3.1.201302201838-r.jar
!path /home/stephane/.m2/repository/com/jcraft/jsch/0.1.46/jsch-0.1.46.jar
]
[INFO] Setting FitNesse variable [org.springframework.version] to [4.2.0.RELEASE]
[INFO] Setting FitNesse variable [java.version] to [1.8.0_60]
[INFO] Setting FitNesse variable [org.springframework.security.version] to [3.2.5.RELEASE]
[INFO] Setting FitNesse variable [project.build.sourceEncoding] to [UTF-8]
[INFO] Setting FitNesse variable [artifact] to [toolbox]
[INFO] Setting FitNesse variable [version] to [0.0.1-SNAPSHOT]
[INFO] Setting FitNesse variable [basedir] to [/home/stephane/dev/java/projects/toolbox]
[INFO] ------------------------------------------------------------------------
[WARNING] No FitNesse Suites or Tests to run! (Set -Dfitnesse.fitnesse.failIfNoTests=false to ignore.)
[INFO] 0 right, 0 wrong, 0 ignored, 0 exceptions
[INFO] 
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:tear-down (default) @ toolbox ---
[INFO] 
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:verify (default) @ toolbox ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.061 s
[INFO] Finished at: 2015-10-26T10:25:17+01:00
[INFO] Final Memory: 19M/205M
[INFO] ------------------------------------------------------------------------
stephane@stephane-ThinkPad-X301:toolbox>

I would like to write a very simple Java test with a Slim fixture, say to check that my business logic add(2, 2) method returns 4.

In which file should I have my wiki test ? In which file should I have my fixture ? How to tell Fitnesse to execute my test ?

UPDATE: My example fixture is:

public class ExampleFixture {

    private String value;
    private String result;

    public ExampleFixture() {
    }

    public void execute() {
        if (value != null) {
            result = Common.trimSpaces(value);
        }
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getResult() {
        return result;
    }

}

and its content:

|Example fixture|
|value|result?|
|some space|somespace|

The last issue, the one about the result[0] not being found, was due to my getter reading result instead of getResult in the fixture content, which now reads: |Example fixture| |value|getResult?| |some space|somespace|

Stephane
  • 11,836
  • 25
  • 112
  • 175
  • What do you see at `http://localhost:9123/FirstTestSuite` ? – Stewart Oct 26 '15 at 09:36
  • Hi Stewart, sorry for the late reply, I had started a new job this week. So, I ran the build with the command: `mvn verify -P wiki` and in the browser I can see: `Contents: SlimTest TestExample` and if I click on `TestExample` then I can see: `See ... example fixture value result? some space somespace`. Then I clicked on the above Test button, and it said: `Tests Executed OK` and `See: example fixture: Bad table! Table has 3 header columns, but row 2 only has 2 columns.`. – Stephane Nov 08 '15 at 09:33
  • I now removed the extra pipe that was one too many and it progressed :-) It now says: `Method result[0] not found in com.thalasoft.fitnesse.ExampleFixture`. I wonder what is the array-like method it is looking for... I have updated my question to display the fixture class. – Stephane Nov 08 '15 at 09:44
  • I changed the getter from result to getResult in the fixture content description, and the output is not fine: `value getResult? some space somespace`. – Stephane Nov 08 '15 at 09:54
  • The automatic testing also works fine now. Running the command `mvn verify`runs the fitnesse test, displaying for a failing (for now on purpose) test: `[INFO] 0 right, 1 wrong, 0 ignored, 0 exceptions`. Now, I'm just left with trying to have the Maven build fail if a fitnesse test fails. – Stephane Nov 08 '15 at 09:58
  • Have you specified `verify` in your plugin config, as suggested by the docs? – Stewart Nov 08 '15 at 11:37
  • I think I did (as seen in my question) as I had based my test on this http://fitnesse-launcher-maven-plugin.googlecode.com/svn/maven/site/fitnesse-launcher-maven-plugin/running.html#Run_FitNesse_Automated_Integration_Tests_auto_mode – Stephane Nov 09 '15 at 10:33
  • Curious. Then the build should fail when 1 or more tests fail ... – Stewart Nov 09 '15 at 10:52

1 Answers1

2

You have placed your fitnesse code under src/test/java/fitnesse/

The default location is actually: src/test/fitnesse/ (Remove the java)

Alternatively, in your pom.xml, configure the directory you wish to use:

<testResourceDirectory>src/test/fitnesse</testResourceDirectory>

See Plugin Configuration docs.


Update:

Since googlecode has been decommissioned, the archive site returns a 404 for some links. I may get around to fixing that some day. Meanwhile, the project is available on Github. If you run maven site and access the created HTML with a browser, the docs should all be complete.

Stewart
  • 17,616
  • 8
  • 52
  • 80
  • I had just noticed that path issue, by looking at the http://localhost:9123/FirstTestSuite page. But now after moving the fitnesse directory to its default src/test/fitnesse location I get redirected to the http://localhost:9123/root?properties page. It looks like a properties page, where I can edit things. I can see a link to my test suite as well. – Stephane Oct 26 '15 at 09:46
  • If running the command mvn verify then I get the result response code of 200 but a fatal error: [Fatal Error] :-1:-1: Premature end of file. – Stephane Oct 26 '15 at 09:50
  • Never had that behaviour before. Does the java-example project work for you? (https://code.google.com/p/fitnesse-launcher-maven-plugin/wiki/Downloads) Alternatively, all I can think is to examine `properties.xml` in the `FirstTestSuite` directory, and check FitNesse docs / wiki for those errors. Which file is giving "premature end" ? – Stewart Oct 26 '15 at 09:52
  • You'd know where I can find some good documentation on how to code a test and its fixture ? I only find old blog articles. I'm surprised there is not more information available. – Stephane Oct 26 '15 at 09:53
  • The java-example project contains examples of both Slim and Fit tests – Stewart Oct 26 '15 at 09:55
  • This is my first test and as I had said in the question, it's a work in progress :-) Hope you don't mind. My src/test/fitnesse/FirstTestSuite/content.txt file contains: !contents !*> setup |import| |eg| *! !2 My first test |Division| |numerator|denominator|quotient?| |10 |2 |5.0 | But my src/test/fitnesse/FirstTestSuite/properties.xml file is totally empty. Again, I'd be very happy to read some resource where it is explained what files need to contain what content. – Stephane Oct 26 '15 at 09:56
  • Examine the java-example project, and maybe post a new question about FitNesse testing itself? – Stewart Oct 26 '15 at 10:06
  • Yes, I'm replicating that project tree and content. I'm not looking at the content.txt file of the first test. I understand the fixture itself is in the branch src/test/java/fitnesse ? – Stephane Oct 26 '15 at 10:08
  • No, not `src/test/java/fitnesse`. As per my answer above, just `src/test/fitnesse`. (Unless you've configured the pom.) – Stewart Oct 26 '15 at 10:12
  • The example project does it so. So you'd have your fixture java file next to the content.txt file of each test ? – Stephane Oct 26 '15 at 10:15
  • Java file? No, java files go in `src/test/java` as normal. The class files will end up on the FitNesse classpath. – Stewart Oct 26 '15 at 10:25
  • If you mean that java files are in `src/test/java/fitnesse/fit`, well that's `src/test/java` and then the *java package* of `fitnesse.fit` – Stewart Oct 26 '15 at 10:27
  • All right, I'll move my fixture back into the `src/test/java` tree then. – Stephane Oct 26 '15 at 10:27
  • Is that okay to have a successful Maven build when the test results say: 0 right, 1 wrong, 0 ignored, 9 exceptions ? Wouldn't it be better to fail the build ? – Stephane Oct 26 '15 at 11:03
  • I'm closing in but still get INFO: FirstTestSuite.SlimTest.TestExample r 0 w 0 0 0.152 seconds [INFO] 0 right, 0 wrong, 0 ignored, 0 exceptions I suppose I should get one 1 right since I have one test. – Stephane Oct 26 '15 at 11:12
  • The purpose of the `verify` goal is indeed to fail the build if one or more tests fail. TBH, this is getting a bit beyond a simple Stackoverflow Q&A. – Stewart Oct 26 '15 at 12:58
  • Thanks for your god support ! I shall find my way :-) – Stephane Oct 26 '15 at 13:46
  • 1
    The provided link of fitness-launcher-maven-plugin doesn't work. – Avinash Anand Dec 27 '18 at 05:19
  • 1
    @AvinashAnand Yes, Googlecode has been decommissioned. The code has been copied to github. I've swapped the link for an archive. – Stewart Dec 27 '18 at 10:56