1 / 10

# Exercises : Testing Java with Fitnesse - PowerPoint PPT Presentation

Exercises : Testing Java with Fitnesse. Alessandro Marchetto FBK - IRST. Exercises with Fitnesses:. 1) Implement and test the “+” operator for pair of integer numbers 2) Extend the “ Add ” class for working with pair of double numbers

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' Exercises : Testing Java with Fitnesse' - joy

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Exercises :Testing Java with Fitnesse

Alessandro Marchetto

FBK - IRST

• 1) Implement and test the “+” operator for pair of integer numbers

• 2) Extend the “Add” class for working with pair of double numbers

• 3) Extend the “Add” class for working with not a not fixed/limited

• set of numbers

• 4) Implement and test other mathematical operators (e.g., “-”, “*”, “/”)

• 5) Test the CurrentAccount class

• 5b) Implement and a change requirement into CurrentAccount

• … all the test cases must be written by using Fitnesse...

1) Implement and test the “+” operator for pairs of integer numbers

• Steps

• Create an eclipse project (called “MathOperators”)

• Write a Java class called “Add” (in a packege called “math”)

• that implements the sum operator between pairs of integer numbers

• In the eclipse project, create a directory called “Fitnesse”

• Add the Fitnesse library to the current eclipse project

• Start Fitnesse in the directory called “Fitnesse”

• Write acceptance test cases for testing the Java class

• - write the Fit-table(s)

•  use the ColumnFixture

• - write the fixture for each table

• Run the test cases, fix bugs (if any) and re-run until no bugs are

• revealed

2) Extend the “Sum” class for working with pair of double numbers

… after the exercise number 1…

- Write other acceptance test cases for the class “Add” in which pairs

of double (not integer) numbers are used to exercute the implemented

Sum

 use the ColumnFixture

- Run the test cases, if there are bugs fix them and re-run until no

bugs are in the class

-- To fix such bug, it is required to implement another method in the “Add”

class that reads double numbers rather than integer numbers

3) Extend the “Sum” class for working with a not limited/fixed set of numbers

• … after the exercises 1 and 2 …

• Write a new class called “AddExtended” that takes a set of numbers (use a LinkedList<Double> as input) and returns the sum of them

• Write other test cases for exerciting the “+” operators by using a

• not limited/fixed set of numbers

• -- e.g., sum three/five integer/double numbers instead of just two

•  use the ActionFixture

• - Run the test cases, if there are bugs fix them and re-run until no

• bugs are in the class

4) Implement and test other mathematical operators (e.g.,“-”, “*”, “/”)

• … after the exercises 1,2 and 3 …

• In mat, write a new Java class called “Subtract” that implements the subtraction between numbers

• Write acceptance test cases for the “Subtract” class

• - In mat, write a new Java class called “Multiply” that implements the multiplication between numbers

• - Write acceptance test cases for the “Multiply” class

• - In mat, write a new Java class called “Divide” that implements the division between numbers

• - Write acceptance test cases for the “Divide” class

5) Test the CurrentAccount class (e.g.,“-”, “*”, “/”)

- Given the following CurrentAccount class:

5) Test the CurrentAccount class (e.g.,“-”, “*”, “/”)

• Create a new eclipse project called “CurrentAccount”

• Create the class “CurrentAccount” in a package “bankAccount”

• Run it, and try to understand the behavior of such class

• identify the most relevant functionality implement

• for each one, identify meaningful execution scenarios

• for each scenario, identify sets of meaningful inputs that can exercise the

• functionality of the class

• Write acceptance test cases for such class

• To do this use the execution scenarios and the meaningful inputs

• Run the test cases, fix bugs (if any) and re-run until no bugs are

• revealed

• Implement the following change requirements: “changing the data

• structure used in the class: Array --> List”

• - re-Run the test cases, fix bugs (if any) and re-run until no bugs are

• revealed

5) Test the CurrentAccount class (e.g.,“-”, “*”, “/”)

• - verify that your test suite include at least the following cases:

• * test cases for testing just the deposit operation

• it must be possible to deposit positive amount of money

• it must be forbidden to deposit negative amount of money

• ColumnFixture

* test cases for testing just the draw operation

•  it must be possible to draw negative amount of money

•  e.g., it must be forbidden to draw positive amount of money

• use the ColumnFixture

• * test cases for testing just the settlement operation

• it depends on the other operations

• call settlment after short (<10) and long (>30) sequences of other operations before calling the settlment operation

• use the ActionFixture

• * test cases for testing sequences of the previous operations

• 5b) Implement a change requirement into CurrentAccount (e.g.,“-”, “*”, “/”)

• - Implement and test the following change requirement:

• * Add a class called “CollectionOfAccounts”

• it contains a list of account (“LinkedList<CurrentAccount>”)

• it has a method to add account to this list

• it has a method to get the account number X in the list

- Notice that X in an integer read from the user (0<X<list.size)

• it has a method to get the accounts in the list from 0 to X. In other terms the method returns the first X accounts that are in the list

• Notice that X in an integer read from the user (0<X<list.size)

• The set of X accounts must be returned into a collection of type: “Collection<CurrentAccount>”

• * Write test cases for the new class

• Initialize the list with 3 account class (with respectively 10, 20, 30 as initial deposit)

• Test each method of the class

• ActionFxture and RowFixture