Section 18.2. Fit Tests for Business Rules


18.2. Fit Tests for Business Rules

Fit tests are for communicating business rules. We have various ways to improve how we express those tests. We start with issues and approaches that apply generally, before tackling ones specific to particular table types.

18.2.1. Development of Tables

With simple business rules that are well understood, it may be easy to design Fit tables for expressing suitable tests in one go. Often, however, various issues have to be understood and dealt with, making it difficult to get under way on writing a test.

Let the tables evolve. Start with simple examples and gradually make them more complicated, as we have shown in earlier chapters. There's no need to make the examples comprehensive to start with; leave detail out until you've made progress and you're ready to tackle it.

Be prepared to change the names in header rows and actions as the table structure evolves. Short names may make sense to you at the time, but will you or others remember what they mean later? Choosing a name may not be easy but can aid in improving understanding.

Tables need to be clear. Can they be named well? Table smells may be the result of badly organized tests or may show that there is a problem in understanding what's required from the stories. Confusion in identifying or clarifying a business rule may be muddying the waters for the test that you're trying to write.

18.2.2. Meaningful Examples

As much as possible, use meaningful examples in tests. It will help everyone better understand how things are. Often, the subtleties of the real world may show us that our ideas about a business rule are too simple, forcing us to deal with all the relevant variations.

Because they often have an insufficient idea of the context in which the systems they build are used, programmers need all the help they can get. It's possible that tests may also be used to automatically generate online and offline user documentation, so it's handy if they're likely to be meaningful to the readers.

The use of meaningful examples is illustrated best in this book by the tests in the chapters in Part II.

18.2.3. Supporting Text

Use headers and comments to organize your test files and make them easier to read. Include descriptions of business rules with the tables or in related pages with FitNesse. Where they're useful, include images that help the reader understand a test and the underlying business rule.

The examples in this book tend to have little supporting text, owing to space limitations. The example test in Section 10.2 on p. 74 is clear in intent and reads easily.

18.2.4. Smell: Meaningless Numbers

Figure 18.1 illustrates this smell. In the first column, numbers are used instead of meaningful names for the three possible values: low, medium, and high, as used in Figure 5.7 on p. 34.

Figure 18.1. Meaningless Numbers in First Column

Discount Group List

value

max

min

%

1

0.00

0.00

0

2

500.00

500.00

3

2

0.00

500.00

5

3

1000.00

500.00

5

3

2000.00

2000.00

10


Meaningless numbers in Fit tables are confusing and require that we repeatedly have to remember or look up what they mean. This makes the tables difficult to read and to check by hand.

18.2.5. Smell: Poor Names

Figure 18.1 also illustrates this smell. The header labels are not very useful: The value of what? The max of what? There's no point in expecting the reader to remember. The full labels, as used in Figure 5.7 on p. 34 are more useful: future value, max owing, min purchase, and discount %.[1]

[1] Even so, we have to assume some knowledge of the particular business area.

Poorly named fixtures, test files or pages, header labels, or actions mean that we and others have to remember what they're about. Good names can be very helpful in reminding us of the purpose of a part of a test. They help us when we introduce a test to someone else. Using the appropriate business terminology can speed things up, as long as uses of a term are not contradictory.

It may seem easier to write a short name for an action because we know what that means now, while we're thinking about it. But consider the many times that someone will read the test or a related one in the future; make it meaningful now.

It may seem easier to not change a name as your thinking about it changes. But build your best approach to meaning into a name. Again, realize that the name is for communicating something, and we need to think of those readers in the future, including ourselves.

Confusion over names may be the result of a quick decision or may point to one or more underlying problems with a Fit test.

  • It is not well understood.

  • Points of view about it differ and need to be resolved.

  • Several tests are combined, which is making it too big.

18.2.6. Smell: Brain Twisters

Look at the booking tests in Figures 18.2 and 18.3. The from and to values in Figure 18.22004/05/06 11:11 and 2004/05/07 09:11differ by the amount of the for values22 hoursin Figure 18.3. Which test is quicker and easier to read? When the time difference is important to the test, make the value obvious.

Figure 18.2. Brain Twister

book

5

 

coffee pot

from

2004/05/13 11:01

to

2004/05/14 09:01


Figure 18.3. Untwisted

book

5

 

coffee pot

on

2004/05/13 11:01

for

22 hours


Keep the following points in mind. Is it difficult to determine whether a particular test is correct? Is there an easier way to express it so that you don't have to work it out? Express the tests as simply as possible, even if that's not the way it's likely to be handled through the user interface.

18.2.7. Smell: Unnecessary Detail

A test should focus on the essence of the business rule, avoiding unnecessary details. For example, because it was not relevant, Joanna's address was not included in any of the tests we saw in earlier chapters of this part. Verbosity in Fit tables simply hides the intent of the test.

The biggest smell arises when Fit tests for general business rules are expressed as operations through the user interface: "Select the Open menu item. Enter Joanna in this field."[2] There are likely to be many user interface operations that can be expressed succinctly as more abstract actions.

[2] Of course, Fit tests can be used to test the operation of that user interface, as distinct from testing the system under test through the user interface.

There is a synergy between this smell and the one in Section 18.6.3. Unnecessary detail causes problems when things inevitably change.

Questions & Answers

Q1:

What if we want to test that the user interface operates correctly?

A1:

Let's say that you want to define important aspects of the user interface itself, such as whether a menu item is enabled, a dialog box is displayed as expected, or a link works on the Web.

Apply the general approach that we have used all along. Develop a test language that best describes what's important to you. For example, it may be convenient to use a RowFixture table to list all the GUI components that are currently enabled.

Don't be constrained by the language of specialized user interface fixtures that are available. The programmers can still make use of such fixtures in the fixtures they develop. It's important that they fulfill your need for expressiveness and conciseness in your Fit tests.

18.2.8. Smell: Tangled Tables

Tangled tables arise when a variety of interrelated tests are mixed together. You can suspect that a test is tangled when it is long and convoluted and/or many tests are similar but differ only in small details.

We avoided creating tangled tables in Section 13.5 on p. 98, when Don decided that "the grace period calculation would be best done independently." Instead, a grace period value was included in the late-return tables, and the calculation of an appropriate grace period, based on the rental period, was done elsewhere.

For a larger example, consider adding tests for bookings of rental items in the RentEz system that was covered over the past few chapters. In developing those tests, we find that several issues need to be clarified.

  • What is a valid period of a booking, independent of the rental items? It can't be in the past. The start date must be before the end date. Are the start and end dates constrained to be at times when the rental company is open?

  • For the rental items to be booked, are they availablenot already booked during all the required period? How much allowance should be made for other clients returning rental items late when they're required for a booking?

  • What happens when a client asks for a booking that can't be satisfied?

  • Are the charges for bookings the same as for immediate rental? When are the payments made?

  • Can bookings be canceled or changed? What happens if a client turns up for the booked rental items but wants to rent only some of them now? Is a fee charged?

  • Do some clients want regular bookings? How often: Every week? Every month? Every public holiday?

It is a trap to try and deal with all these issues at once in a set of tangled tests. It is essential to separate the business rules involved to be clear about them.

  • We could use one ColumnFixture or CalculateFixture table to test the validity of date periods, independent of the holiday issue. Validation in general is usually best done in this way, separately from any workflow tests.

  • Another test or group of tests could set up existing bookings with a SetUpFixture table and then check whether various new bookings can be accepted with a ColumnFixture or CalculateFixture table. There are many cases to check for here, as there are many ways in which existing and potential bookings can overlap.

  • Separate ActionFixture or DoFixture tests will be needed to define what happens when a booking can/cannot be made.

  • It should be straightforward to find out how charging is handled and to change that without having to change much else.

See Section 18.3.2 for one way to untangle tests.

18.2.9. Smell: Split Values

As we saw in Section 16.3 on p. 131, it was worthwhile handling time durations as single values in a cell instead of using several cells. For example, Figure 18.4 shows a table in which hours, days, and weeks are in separate columns. However, this makes it a little more difficult to read. More important, it requires that all columns be filled in, even if they're not relevant, such as 0 for most of the hour values in Figure 18.4.

Figure 18.4. Split Values

$

5.00

per hour

45.00

per day

200.00

per week

hours

days

weeks

days()

weeks()

0

4

0

4

0

0

5

0

0

1

5

6

0

0

1


Figure 18.5 shows a refactored table in which the duration of hours, days, and weeks is a single value.

Figure 18.5. Duration as a Value

$

5.00

per hour

45.00

per day

200.00

per week

duration

 

fair

4 days

 

4 days

5 days

 

1 week

6 days 5 hours

 

1 week


In general, consider whether a value that is split over several cells would be better expressed as a single value in a single cell. It can be false economy for programmers to avoid writing fixture code to handle such values or to improve the expressiveness of Fit tests in general. Putting a little effort into the fixtures can lead to better tests and to reductions in the efforts of the test writer and the reader.

18.2.10. Smell: Long Tables

If a table is very long, perhaps it can be made clearer by splitting it into several tables. There may be a way of organizing it so that the separate tables are meaningful units. We can then explain each of the tables with supporting text (Section 18.2.3).

18.2.11. Custom Tables

As we mentioned in Chapter 11, your tests may have a pattern that you're unable to exploit with the existing fixtures. It means that the tests are larger than they need to be, because they don't express things directly. People have a powerful visual ability that can quickly process and understand tests that show important associations spatially.

So go ahead and make up a custom table, and talk to the programmers about making a fixture for it. For a few examples, see Chapter 11.



    Fit for Developing Software. Framework for Integrated Tests
    Fit for Developing Software: Framework for Integrated Tests
    ISBN: 0321269349
    EAN: 2147483647
    Year: 2005
    Pages: 331

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net