An Example of How to Use the C++ FIT Framework

 

mfeathers@objectmentor.com

 

 

 

You can embed FIT tests in any document that can be rendered in HTML.  This little document describes how to use FIT, but if you save it as HTML, you can run it through FIT.

 

The example in this document is a little payroll application.  It is something I pieced together while students were doing exercises during a class I was teaching.  I’ve added it to the “eg” directory of the FIT distribution to give an example of how to use multiple tables to test an application.

 

 

The first thing we have to do is start the application:

 

PayrollFixtures.Control

 

start

PayrollTestServer

 

 

The Control class is a class that is accessed through the PayrollFixtures DLL.  Control subclasses ActionFixture.  Here we are using it to start the application using PayrollTestServer.  That class holds onto the payroll database; when it is created all subsequent tables can use it.  This doesn’t happen automatically.  Take a look at the code to see how the database is accessed.

 

Now that we have started the application, we can start to input data.  The following table inputs a set of employees that the application will pay:

 

PayrollFixtures.AddEmployees

 

 

name

employeeID

hourlyRate

Michael

1

100

Jeff

2

100

 

 

PayrollFixtures.AddEmployees is a subclass of ColumnFixture.  In this case, the fixture does not check values.  I overrode a method of the class to add each row to the payroll application as input.

 

 

 

 

The following table: PayrollFixtures.AddTimeCards uses the same pattern:

 

PayrollFixtures.AddTimeCards

 

employeeID

hours

1

40

2

20

 

 

Now we can look at a table which essentially “runs” payroll and shows the output.  It is a subclass of RowFixture, which is the most complicated of the standard FIT fixtures.  What it does is try to match all of the rows in the table to objects that are produced by the application:

 

 

PayrollFixtures.OutputCommands

 

id

payment

1

4000

2

0

 

 

Notice that the success cases are marked in green when this table is run.  Each line is a check with a particular employee ID and payment about.  If there were rows here that were not in the program’s output or objects in the output that were not in the table, they would be marked as “missing” or “surplus.”

 

And that is an example of FIT.  The best thing that you can do is add rows or modify values in this document to get a feel for the framework.  You should also take a look at how the payroll application is tied into the framework.  All of the source for the example is in subdirectories of the eg directory.

 

Ooops.  I forgot to close the application:

 

 

PayrollFixtures.Control

 

end

PayrollTestServer