Port of schuchert.wikispaces.com


FitNesse.Tutorials.0.Java

FitNesse.Tutorials.0.Java

Create Eclipse Project

In a nutshell, you are going to create a Java project, add some classes and then add the bin directory to the FitNesse path so that FitNesse can find and execute your Java Fixtures.

You can either start with source from github and skip to the next section or:

Create Fixture for Test Table

Determine Where Eclipse Stores Your Class Files

Next, you’ll need to know where Eclipse is placing your compiled Java classes.

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path="src"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
	<classpathentry kind="output" path="bin"/>
</classpath>

Add your code to Path

!path /Users/schuchert/src/fitnesse-tutorials/DVR/bin

|import|
|com.om.example.dvr.fixtures|
!define TEST_SYSTEM {slim}

!path /Users/schuchert/src/fitnesse-tutorials/DVR/bin

|import|
|com.om.example.dvr.fixtures|
 
!define COLLAPSE_SETUP {true}
!define COLLAPSE_TEARDOWN {true}
 
!|Create Programs                                        |
|Name |Channel|DayOfWeek|TimeOfDay|DurationInMinutes|id? |
|House|4      |Monday   |19:00    |60               |$ID=|

You have two tables in your page. The first table is an import table, it tells FitNesse to import that package or namespace (e.g. if you’re working with .Net). That is, when looking for fixture classes (classes that process tables), look in this package. If you want to import multiple packages or namespaces, use multiple rows (or duplicate the entire table).

The second table is a decision table. (Those familiar with Fit may recognize the similarity between Decision Tables and Column Fixtures.) The first row names a class, CreatePrograms in this case. You created this class above. The second row names the columns. Column headers that do not have a question mark in their name require a “set” method to back them. Column headers with a question mark require a method that returns a value. In our case we have 6 columns, so we need to add 6 methods, 5 setters and one method which returns a value. Here’s the complete “stub” class to get this table fully passing:

package com.om.example.dvr.fixtures;

public class CreatePrograms {
    private String name;
    private int channel;

    public void setName(String name) {
        this.name = name;
    }

    public void setChannel(int channel) {
        this.channel = channel;
    }

    public void setDayOfWeek(String dayOfWeek) {
    }

    public void setTimeOfDay(String timeOfDay) {
    }

    public void setDurationInMinutes(int durationInMinutes) {
    }

    public String id() {
        return String.format("[%s:%d]", name, channel);
    }
}

Verify Your Tests Pass

Return and Complete Your Tutorial


Comments

" Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.