core-jgi/fitnesse/FitNesseRoot/FitNesse/UserGuide/TwoMinuteExample/content.txt

60 lines
4.7 KiB
Plaintext
Raw Normal View History

!*< Hidden
!define TEST_SYSTEM {slim}
*!
[[A One-Minute Description][OneMinuteDescription]]
!1 An Example !-FitNesse-! Test
If you were testing the division function of a calculator application, you might like to see some examples working. You might want to see what you get back if you ask it to divide 10 by 2. (You might be hoping for a 5!)
In FitNesse, tests are expressed as tables of '''input''' data and '''expected output''' data. Here is one way to specify a few division tests in FitNesse:
|eg.Division|
|numerator|denominator|quotient?|
|10 |2 |5.0 |
|12.6 |3 |4.2 |
|22 |7 |~=3.14 |
|9 |3 |<5 |
|11 |2 |4<_<6 |
|100 |4 |33 |
This style of FitNesse test table is called a [[Decision Table][SliM.DecisionTable]], each row represents a complete scenario of example inputs and outputs. Here, the "numerator" and "denominator" columns are for inputs, and the question mark in the "quotient?" column tells FitNesse that this is our column of expected outputs. Notice our "10/2 = 5.0" scenario. Try reading it as a question: ''"If I give you a numerator of 10 and denominator of 2, do I get back a 5?"''
!3 Running our test table: Click the Test button
Before we do another thing, let's run this test table. See the little blue and white '''Test''' button in the upper-left, just below the !-FitNesse-! logo? Click it and see what happens.
Ah, color! In the green cells, we got back the expected values from our code. When we divided 10 by 2, we expected and got back 5. When we divided 12.6 by 3, we expected and got back 4.2.
What about red? A cell turns red when we get back a different value than what we expected. We also see two values: the '''expected''' value and the '''actual''' value. Above we expected 33 back when we divided 100 by 4, but we got back 25. Ah, a flaw in our test table. That happens!
Notice also the comparisons. 22/7 is approximately equal (~=) to 3.14. 9/3 is less than 5. 11/2 is between 4 and 6.
!3 Creating the Table
How did we put that test table on this page in the first place? Well, we used FitNesse itself to do it!
FitNesse is a [[wiki][http://wiki.org/wiki.cgi?WhatIsWiki]], which is a style of web server that allows any visitor to make any edits, including changing existing pages and creating new pages. A simple markup language lets you easily create headings, make text bold, underline, and italic, create bulleted lists, and do other kinds of simple formatting. You can read more about it on EditingFitNessePages.
Once you download FitNesse to your own computer, you can edit any page simply by clicking on the Edit button on the left (just below the Test button). If you are reading this page on your own copy of FitNesse on your own machine, you can click the Edit button and see for yourself. (To learn more, see DownloadingAndInstallingFitNesse.)
The wiki markup for our table above (with some omissions) looks like this: {{{
|eg.Division|
|numerator|denominator|quotient?|
|10 |2 |5 |
|12.6 |3 |4.2 |
|100 |4 |33 | }}}
The vertical bars delimit table cells. For this table, there is not much more too it than that. You don't have to line up the vertical bars this way; we just do it to make it easier to read.
Note that if you don't like mucking about with a markup language at all, you can create your test tables in a spreadsheet such as Excel, copy them to the clipboard, and use the '''Spreadsheet to Fitnesse''' button on the Edit page to have FitNesse format your table properly for you.
'''Note''' also that if you change "eg.Division" to any other name, you may need to use a ! before the fixture to avoid confusing FitNesse with [[!-WikiWord-!][WikiWord]]s (see MarkupTable)
!3 Organizing Tests
FitNesse test tables live on test pages (such as this one). There are several TestTableStyles. As your sets of test pages grows, you can organize them into hierarchical TestSuites.
!2 Learning More
!3 You Have Choices!
How shall you spend the next few minutes? It's up to you.
!3 More Technical Detail...
If you are more interested in learning how to create the code that makes test tables work, see FixtureCode. If you want to start diving into installing and running FitNesse, check out DownloadingAndInstallingFitNesse.
!3 More Usage Detail...
If you are more interested in why and how to get teams to use FitNesse, see AcceptanceTests. If you want to learn how to create and run FitNesse tests, check out EditingFitNessePages, CreatingTestTables, and TestTableStyles.
!3 Or Take Your Own Path
Finally, if you want to zoom back out and look at all of the FitNesse topics, check out the table of contents on the <UserGuide.