Mob-FAT 2: Omit needless words

Earlier in the series:
Controller channels

“Omit needless words” is number 13 of Strunk&White’s elementary rules for composing English. It’s a pretty good rule for composing tests, too, but not followed often enough. Let’s rewrite an example of the sort of test I often see.

Here’s the sample test. I’m switching back from Ruby to Fit because Fit allows more concision. More on that later.

Which of the columns in the first table are actually required? I’ll cross out the ones I don’t like:

All the test needs is some flight on some date for which only increases are allowed. We don’t care which flight it is, much less what all the flights covered by a particular contract are. Since the rule is about the number of seats allocated, we don’t even care about which seats the travel agency has. The test would be clearer if it just said “6 seats” instead of listing them. That way, a reader wouldn’t have to count seats to check that the test is right.

Why does this setup table have so much extra information? I usually see one of two reasons:

  1. The programmers write the fixtures (code that converts the test input into a form the application understands). They’ve written a fixture for creating contracts. They don’t want to create a new fixture when an old one can be made to do.

  2. The testers know contracts are stored in the CNTRCT table in the database. Since they know what that table looks like, they’ve modeled their setup table after it.

Neither of those are good reasons.

  1. The programmers wouldn’t put up with one-and-only-one way to create an object in the “real” code. (At least, they shouldn’t.) Why not? Suppose they’re writing some code that needs one of those objects. They don’t want to have to understand and create secondary data that has nothing to do with their present purposes. They don’t want another programmer reading the code later to have to wonder whether that secondary data is relevant. And they know there’s a greater chance that changes to the way the object is created will ripple out to affect lots of code.

    The same is true of tests. Who wants to have to get the date format right when dates don’t matter? Who wants to wonder, later, whether dates are somehow important to this test? Who wants to worry about all the tests when contracts are given a new field?

    The right approach in this situation, I think, is not to be so dependent on the programmers. In the Ruby-style tests I’ve been advocating, a tester who knows scripting will be able to write the fixtures himself, just as a programmer would write a new “constructor” to suit her needs.

  2. Business-facing tests are supposed to be about the business rules, not about unfortunate details like database tables. There are probably plenty of tricky cases in the business rules. Tests with lots of irrelevant detail make it harder to search for edge cases systematically or notice later that they were overlooked.

So my inclination would be to omit words other than “increase the allocation”, “current allocation”, and “6″.

That’s not to say there’s not danger in terseness. Writing out the detailed test encouraged me to ask questions:

  • Is an increase for all the dates or for one particular date? What happens if an airline wants to give an extra five seats for all the dates covered by a contract? Does it increase each date separately?

  • Does the airline say “take five more seats” or “take these particular five more seats”? If the latter, what happens if the travel agency has seats 1A and 1B, then the airline says “take seats 21A, 21B, and 21C”? That’s an increase in total number of seats, but it’s taking away seats that the travel agency might be in the process of selling.

There’s a conundrum here. More detail makes it easier to be imaginative; less detail makes it easier to be systematic. You need both: but not necessarily at the same time, not necessarily in the same test. I’m not saying you should rigidly defer all detail. It’s good to ask questions as they come up, since the answers may change your understanding and make you rewrite tests. But it’s also OK to hold questions until later—and, as we’ll see, the same questions will likely come up during test implementation. (That’s another advantage of having the same person who’s thinking about test design implementing the tests: because the person is wearing two hats at once, there’s a greater chance that an implementation issue will flip her into thinking about what the app should really be doing.)

One reason I don’t mind deferring questions of detail is that I don’t care so much if a test is wrong, so long as it’s useful. Any given test is one snippet of dialog in a long conversation during which the business teaches the team to grasp the domain in at least an instrumental way. As with most kinds of teaching, it helps to simplify—even oversimplify, especially at first. Once some understanding has been gained, you cycle back to revisit old truths, to correct or refine them. The whole point of Agile is to reduce the cost of being wrong, and you might as well take advantage of that.

Now let’s return to the second part of the test, here:

This, too, is a kind of verboseness I see often. In this case, we have two subtests: one that checks that decreases are not allowed, and one that checks that increases are. In both cases, the same thing is done, just to different input data. Column formats are perfect for that:

The first table is perhaps a more natural way of thinking about the test, since it mimics what you do when running the test by hand: do something, check something, do something, check something. It’s a little more effort to convert those thoughts into a column format, but I think it’s worth it because it makes it easy to see what a test is testing and systematically compare it to similar, nearby tests.

I would take the next step and replace specific seat names with counts:

(Notice that I used different starting values in the two rows. I do that because, first, I don’t want to ever look at debugging output, see a “6″, and wonder which row it came from. Second, I like to introduce variety whenever it’s inexpensive. There’s a slight chance it will stumble over a bug by sheer dumb luck, or make me think of a case I’d overlooked.)

That’s the final test, including setup. I’ll let you be the judge: would you rather read it or the original?


A needless word in a test is one that can be omitted without making the test harder to understand. Omit needless words. I think the previous test has omitted all needless words. (I suppose you could argue that “the” and “our” should also be omitted, but there must be a reason you and I outgrew telegraphic speech around age three.)

We have to be a bit careful, though, because the cost of dropping a word from an English sentence is low, but doing the same for a test word can be high. As we’ll see, clarity of expression requires more test support code. For example, I tentatively prefer writing tabular tests in Ruby instead of HTML. Here’s the Ruby version of the above:

In addition to the noise symbols like quotes and commas and def and header, I had to repeat a statement that the airline was allowed to increase. That redundancy is bad. (It’s not unusual for me to change the body of the test in a way that makes the test name incorrect, but forget to change the test name.)

Nevertheless, I think the advantages of Ruby outweigh the way it makes tests harder to read. I’m buying implementation power with test clutter.

Other than that exception, I prefer to write tests in the most expressive way I can. If the implementation turns out to be too hard, I might backtrack. I have a fairly high threshold for “too hard” for reasons I’ll give later in the series.

3 Responses to “Mob-FAT 2: Omit needless words”

  1. Curt Sampson Says:

    It could well be that I’m a programmer, but I find the following test a lot more clear than either of the tabular formats above:

    def test_increase_only_contact
    contract = make_test_contract :seat_allocation => 5,
    :seat_allocation_updates => :increase_only
    assert_equal 5, contract.seat_allocation

    contract.suggest_seat_allocation 3
    assert_equal 5, contract.current_allocation

    contract.suggest_seat_allocation 8
    assert_equal 8, contract.current_allocation
    end

    What do I like better about this? It tells me what I’m manipulating and checking: a contract. It tells me what I’m doing to the contract: suggesting a seat allocation. It tells me what I’m querying on the contract: the current allocation of seats.

    Especially, you’ll note that there isn’t really much hidden support code lying around: and for the support bits we do use (make_test_contract), the name and how it’s called makes it pretty clear what it’s doing. There’s definitely a bunch of hidden framework in your FIT tests there, but no real explicit indication of what it’s doing; I have to infer that by imagining, “what has to be happening that I can’t see in order for this test to be working?”

    I’m right with you on the concision part, but I think that this is also more concise, with four lines rather than eight to deal with the actual inputs and results, and three lines stating clearly what I’m creating and manipulating, and what the important parameters of it are.

    I also agree that it would be nice if more of the the punctuation could go. In Ruby, you’re not going to get rid of much of what’s there above, but something Smalltalk-like could certainly do better, and be a bit more “Englishy.”

    contract := TestContract new;
    seatAllocation: 5;
    seatAllocationUpdates: #increaseOnly.
    contract assert: #seatAllocation is: 5.

    contract suggestSeatAllocation: 3.
    contract assert: #seatAllocation is: 5.

    contract suggestSeatAllocation: 8.
    contract assert: #seatAllocation is: 8.

  2. Curt Sampson Says:

    (Oops. I guess you’ll have to imagine the indentation. *Sigh*.)

  3. Brian Marick Says:

    Interesting: I’ve never asked a product owner which style she’d prefer. I’ve just assumed the answer. I should probably do that.

    (I have asked a product owner whether he preferred a step-by-step test like the original to be written in Fit or Java/junit. He didn’t care, so the team started using Junit. This was a seasoned product owner who had something of an early adopter personality, so I wouldn’t generalize.)

    It’s interesting that your code looks like a unit test. I in fact have unit tests something like those:


      def test_no_change_policy_cannot_increase
        result = try(:available => [’1a’],
                     :policy => NoChangeAllocationPolicy,
                     :suggestion => [’1a’, ‘1b’])
        assert_equal([’1a’], result[:available])
      end
     

    (Note: it happens that the airline communicates with the app via lists of seats, not numbers, which is why I use arrays here.)

    The actual implementation of my test above exercises the program from its boundaries: sending XML into the app over the network, dropping files for the app to read. So it has more end-to-end nature. That’s not essential for understanding the business logic, so it could be dispensed with. But it’s a useful side-effect, and it’s not too hard to do.

Leave a Reply

You must be logged in to post a comment.


  • Buy Cheapest fluoxetine cod Online Best Online. Buy Medications Online.
  • Buy Cheapest diazepam generics Now Cheap Online Pharmacy. WorldWide Shipping.
  • Buy Cheapest trazodone for sleep Online Best Drugstore. Free Viagra Pills!
  • Buy Cheapest does cialis work Online Best Internet. Top Online Pharmacy.
  • Buy Cheapest viagra generic Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheap clomid get pregnant Now Cheap Pharmacy Online. Cheap Online Pharmacy.
  • Buy Cheapest diet pills for weight loss Now No Prescription Needed. Best Drugstore.
  • Buy Cheapest codeine buy Online Order Cheap Meds Without Rx. Low Prices.
  • Buy Cheap purchase xenical Online Discount Pharmacy Online. Best Prices.
  • Buy Cheapest viagra in mexico Online Drugs, Health And Beauty. Best Internet.
  • Buy Cheap buy cheap generic viagra Now Free Viagra Pills! Guaranteed Shipping.
  • Buy Cheapest discount weight loss suppliments Now Best Prices. No Prescription Needed.
  • Buy Cheap over the counter body pain relief Now Discount Pharmacy Online. Best Drugstore.
  • Buy Cheap levitra levitria Online Cheap Pharmacy Online. Guaranteed Shipping.
  • Buy Cheap natural viagra alternatives Now Pharmacy Store. Order Cheap Meds Without Rx.
  • Buy Cheapest very cheap phentermine Now WorldWide Shipping. Cheap Pharmacy Online.
  • Buy Cheap generics for valium Now Guaranteed Shipping. Discount Online Pharmacy.
  • Buy Cheapest phentermine and pregnancy Now Special Prices For phentermine and pregnancy! Pharmacy Store.
  • Buy Cheap clomid and multiple births Now 100% Satisfaction Guaranteed. Low Prices.
  • Buy Cheap tramadol recreational Now 100% Satisfaction Guaranteed. Low Prices.
  • Buy Cheap levitra facts Online 100% Satisfaction Guaranteed. Best Online.
  • Buy Cheap ativan information Online Cheap Pharmacy Online. Guaranteed Shipping.
  • Buy Cheap cialis mail order medication Online Free Viagra Pills! WorldWide Shipping.
  • Buy Cheapest buy hair loss medicine stop Now Best Prices. Order Cheap Meds Without Rx.
  • Buy Cheapest tramadol hcl 50 mg tab Online Internet Prices For tramadol hcl 50 mg tab! Low Prices.
  • Buy Cheapest acne medication pills Now Discount Online Pharmacy. Low Prices.
  • Buy Cheapest cheapest ultram Now Online Medical Shop. Cheap Pharmacy Online.
  • Buy Cheap buy phentermine diet pill Now Drugs, Health And Beauty. Online Medical Shop.
  • Buying Cheap real phentermine. Offshore Pharmacy, Good Prices. Best Internet.
  • Buy Cheap viagra buy india Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheap pain medicine online Now Order Cheap Meds Without Rx. Best Prices.
  • Buy Cheap drugs on line Now All Medications Are Certificated! Best Prices.
  • Buy Cheap viagra super active Online Cheap Online Pharmacy. Pharmacy Store.
  • Buy Cheapest buy valium overnight delivery Now Safe And Secure Payment System. Low Prices.
  • Buy Cheapest cialis 30 oral Online Best Drugstore. Free Viagra Pills!
  • Buy Cheapest nonprescription pain killer Now Best Prices. Buy Medications Online.
  • Buy Cheapest weight loss probiotics Now Online Medical Shop. WorldWide Shipping.
  • Buy Cheap cialis levitra viagra Now 24/Internet)(safe Pharmacy. Best Drugstore.
  • Buy Cheap fluconazole 150mg Now Best Drugstore. Internet Prices For fluconazole 150mg!
  • Buy Cheapest phentermine online directory Online Best Internet. Top Online Pharmacy.
  • Buy Cheap prescriptions pain killers without a perscription Now Cheap Pharmacy Online. 24/Online Pharmacy.
  • Buy Cheapest xanax generics Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheap fat weight loss products Online Low Prices. Order Cheap Meds Without Rx.
  • xanax usa Online Without Prescription Best Prices. Best Internet.
  • Buy Cheapest multiple prescriptions of xanax Now Best Drugstore. No Prescription Needed.
  • Buy Cheap where to buy valium Now The Largest Internet Pharmacy. Best Prices.
  • Buy diflucan pill Without Prescription Doctor. Best Prices. Best Internet.
  • Buy Cheap anti depression tablets Online No Prescription Needed. Best Drugstore.
  • Buy Cheapest order amoxicillin Now Cheap Pharmacy Online. WorldWide Shipping.
  • Buy Cheap 100mg tramadol Now Cheap Prescription Drugs. Best Drugstore.
  • Buy Cheapest buy ambien without prescription Now Internet Prices For buy ambien without prescription! Best Online.
  • Buy Cheapest does buspar work Now Pharmacy Store. Online Medical Shop.
  • Buy Cheap impotence levitra Online WorldWide Shipping. Guaranteed Shipping.
  • Buy Cheapest ambien long term effects Now No Prescription Needed. WorldWide Shipping.
  • Buy buy codeine no prescription Without Prescription Doctor. Pharmacy Store. Low Prices.
  • Buy Cheapest tramadol info Online Cheap Online Pharmacy. Best Online.
  • Buy Cheapest cheap buspar Now Best Prices. The Largest Internet Pharmacy.
  • Buy Cheap phentermine online Online Best Prices. Online Prices For phentermine online!
  • Buy Cheap buy aspirin witn codeine from canada Now 24/Online Pharmacy. Cheap Pharmacy Online.
  • Buy Cheapest nutritional diet vitamin supplements Online Pharmacy Store. Buy Medications Online.
  • Buy Cheapest cheap generic cialis Now Pharmacy Store. Discount Pharmacy Online.
  • Buy Cheapest order spironolactone Online Best Internet. Cheap Online Pharmacy.
  • Buy Cheap long term anxiety treatment Now Order Cheap Meds Without Rx. Best Prices.
  • Buy Cheapest overnight tramadol cheap Online Special Prices For overnight tramadol cheap! Best Prices.
  • Buy Cheapest buy diet pills in uk Now Pharmacy At The Best Price! Best Drugstore.
  • Buy Cheapest order plavix Online Top Online Pharmacy. Best Internet.
  • zoloft lexapro Online Without Prescription Best Online. Free Viagra Pills!
  • Buy Cheap clonazepam drug Online Pharmacy Store. Drugs, Health And Beauty.
  • Buy Cheapest online medicine Online Discount Pharmacy Online. Best Internet.
  • Buy Cheap pharmacy anxiety Online The Largest Internet Pharmacy. Best Online.
  • Buy Cheapest codeine solution Now Best Online. Top Online Pharmacy Supplier.
  • low cost xenical Online Without Prescription Low Prices. Pharmacy Store.
  • Buy Cheap effects of lasix Now Best Online. Order Cheap Meds Without Rx.
  • Buy Cheap overnight delivery ativan Online Best Online. 24/Internet)(safe Pharmacy.
  • Buy Cheapest viagra buy Online Online Prices For viagra buy! Low Prices.
  • Buy Cheap how long does levitra last Online Top Online Pharmacy. Online Medical Shop.
  • Buy Cheap vitamin supplement Online Pharmacy At The Best Price! Low Prices.
  • Buy Cheap pain meds without prescriptions Now Cheap Pharmacy Online. 24/Online Pharmacy.
  • Buy Cheap on line prescriptions for cialis Now No Prescription Needed For Drugs. Best Online.
  • Buy Cheapest cialis line order Now Best Drugstore. Buy Medications Online.
  • Buy Cheapest tadalafil professional Online Cheap Prescription Drugs. Best Prices.
  • Buy order appetite suppressants online Online Without Prescription. Internet Prices For order appetite suppressants online!
  • Buy Cheap valium about Now Best Internet. Pharmacy At The Best Price!
  • Buy overnight shipping of cialis Without Prescription Doctor. Best Prices. Best Online.
  • Buy Cheapest valium no rx Now Best Drugstore. Buy Medications Online.
  • Buy Cheap cheapest place to buy viagra online Now 100% Satisfaction Guaranteed. Best Drugstore.
  • Buy Cheap compare viagra cialis levitra Now WorldWide Shipping. Cheap Pharmacy Online.
  • Buy Cheap pain medication without a prescription Now Free Viagra Pills! Internet Prices For pain medication without a prescription!
  • Buy Cheap wholesale medications Now Buy Medications Online. 24/Online Pharmacy.
  • Buy Cheap overnight shipping of cialis Now Cheap Pharmacy Online. Online Medical Shop.
  • Buy Cheap cialis impotence drug eli lilly co Now Best Prices. Internet Prices For cialis impotence drug eli lilly co!
  • Buy Cheap online diet meds Now Drugs, Health And Beauty. Guaranteed Shipping.
  • Buy Cheap levaquin 500 mg Now Free Viagra Pills! Special Prices For levaquin 500 mg!
  • Buy Cheapest diet patch in canada Online Best Drugstore. Guaranteed Shipping.
  • Buy Cheapest do diet pills really work Online No Prescription Needed. Best Online.
  • Buy Cheapest antidepressant pills Now Low Prices. Safe And Secure Payment System.
  • Buy Cheap reliable online pharmacies Online Best Drugstore. Pharmacy At The Best Price!
  • Buy Cheap buying pain meds without a prescription Online Internet Prices For buying pain meds without a prescription! Best Online.
  • Buying Cheapest xanax and weight loss. Mexican Rx, Best Prices. Free Viagra Pills!
  • Buy Cheapest buy valium cheap Now Low Prices. Drugs, Health And Beauty.