Testing on the Toilet

Feb. 21, 2008

Too Many Notes Tests In the movie Amadeus, the Austrian Emperor criticizes Mozart's music as having “too many notes.” How many small tests are “too many” to test one function? Consider the method decide: public void decide(int a, int b, int c, int d, int e, int f) { if (a > b || c > d || e > f) { DoOneThing(); } else { DoAnother(); } // One-letter variable names are used here only because of limited space. } // You should use better names. Do as I say, not as I do. :-)

How many tests could we write? Exercising the full range of int values for each of the variables would require 2192 tests. We'd have googols of tests if we did this all the time! Too many tests. What is the fewest number of tests we could write, and still get every line executed? This would achieve 100% line coverage, which is the criterion most code-coverage tools measure. Two tests. One where (a > b || c > d || e > f) is true; one where it is false. Not enough tests to detect most bugs or unintentional changes in the code. How many tests to test the logical expression and its sub-expressions? If you write a test of decide where a == b, you might find that the sub-expression a > b was incorrect and the code should have been a >= b. And it might make sense to also run tests where a < b and a > b. So that's three tests for a compared to b. For all of the parameters, that would 3 * 3 * 3 = 27 tests. That's probably too many. How many tests to test the logical expression and its sub-expressions independently? Consider another version of decide, where the logical sub-expressions have been extracted out: public void decide(int a, int b, int c, int d, int e, int f) { if (tallerThan(a, b) || harderThan(c, d) || heavierThan(e, f)) { DoOneThing(); } else { DoAnother(); } } boolean tallerThan(int a, int b) { return a > b; } // Note “package scope” boolean harderThan(int c, int d) { return c > d; } // rather than public; JUnit boolean heavierThan(int e, int f) { return e > f; } // tests can access these.

We can write four tests for decide. One where tallerThan is true. One where harderThan is true. One where heavierThan is true. And one where they are all false. We could test each of the extracted functions with two tests, so the total would be 4 + 2 * 3 = 10 tests. This would be just enough tests so that most unintentional changes will trigger a test failure. Exposing the internals this way trades decreased encapsulation for increased testability. Limit the exposure by controlling scope appropriately, as we did in the Java code above. How many tests is too many? The answer is “It depends.” It depends on how much confidence the tests can provide in the face of changes made by others. Tests can detect whether a programmer changed some code in error, and can serve as examples and documentation. Don't write redundant tests, and don't write too few tests.

More information, discussion, and archives: http://googletesting.blogspot.com Copyright © 2007 Google, Inc. Licensed under a Creative Commons Attribution–ShareAlike 2.5 License (http://creativecommons.org/licenses/by-sa/2.5/).

too_many_tests - NeoOffice Writer Code

Testing on the Toilet. Feb. 21, 2008. Too Many Notes Tests. In the movie Amadeus, the Austrian Emperor criticizes Mozart's music as having “too many notes.” How many small tests are “too many” to test one function? Consider the method decide: public void decide(int a, int b, int c, int d, int e, int f) { if (a > b || c > d || e > f) {.

188KB Sizes 1 Downloads 132 Views

Recommend Documents

public_static_cling - NeoOffice Writer Code
Jun 26, 2008 - "always throws an exception," "only returns a TheirEntity if the id is a prime," and so forth. These kinds of tests would've been impossible before this refactoring. More information, discussion, and archives: http://googletesting.blog

TimeIsRandom.odt - NeoOffice Writer Code
3 Apr 2008 - There are two barriers to effectively testing this method: 1. There is no easy way to test corner cases; you're at the mercy of the system clock to supply input conditions. 2. When nextMinuteFromNow() returns, the time has changed. This

too_many_tests - NeoOffice Writer Code
Testing on the Toilet. Feb. 21, 2008. Too Many Notes Tests. In the movie Amadeus, the Austrian Emperor criticizes Mozart's music as having “too many notes.” How many small tests are “too many” to test one function? Consider the method decide:

TotT-StroopEffect - NeoOffice Writer Code
Feb 7, 2008 - RED, GREEN, BLUE, ... (Try it now!) 2. ...say all 25 colors out loud: GREEN, YELLOW, WHITE... (Try it now!) Did the second task require more time and effort? If so, you're experiencing the Stroop Effect, which roughly says that when a l

public_file_flakiness - NeoOffice Writer
Apr 17, 2008 - The callers of CreateGapLease can continue invoking it as usual, but the unit test can pass in a different path: def testCreateGapLease(self):.

public_file_flakiness - NeoOffice Writer
Apr 17, 2008 - In this case, clearing the file at the start of the test can reduce its brittleness: def testCreateGapLease(self): if os.path.exists(lease_file):. RemoveFile(lease_file) ... Unfortunately, this doesn't completely eliminate the flakines

testng-on-the-toilet - NeoOffice Writer Code
20 Mar 2008 - TestNG is a test framework for Java unit tests that offers additional power and ease of use over JUnit. Some of TestNG's features will help you to write your PirateShip tests in such a way that you'll be well prepared to take on the Adm

testng-on-the-toilet - NeoOffice Writer Code
Mar 20, 2008 - TestNG's capacity for running tests in parallel. You can do this in the definition of ... in an XML file) with the parallel and thread-count attributes.

canberraplanreview.odt - NeoOffice Writer
For Marco Polo in Italo Calvino's Invisible Cities,1 Venice is the one true city from whose structure all possible cities can be deduced. In that case, Venice is the reciprocal of Canberra, whose plan was abstracted from all the many actual cities, b

Public Friends You Can Depend On.odt - NeoOffice Writer
Jun 12, 2008 - More information, discussion, and archives: http://googletesting.blogspot.com. Copyright © 2007 Google, Inc. Licensed under a Creative ...

Public Friends You Can Depend On.odt - NeoOffice ... Code
Jun 12, 2008 - A Stub overrides the real object and returns hard-coded values. Testing with ... implementing an in-memory database, or using a fake BigTable.

Letter Writer
Use specifics (precise character names and events)?. YES. NO. • Talk about book events in a way that suggests familiarity with causes, effects, outcomes, etc.? YES. NO. • Convey maximum information with minimal words? YES. NO. • Connect the ref

Eus, Personae e Grupos.odt - NeoOffice Writer.pdf
Eus, Personae e Grupos.odt - NeoOffice Writer.pdf. Eus, Personae e Grupos.odt - NeoOffice Writer.pdf. Open. Extract. Open with. Sign In. Main menu. Whoops!

Becoming a Writer
questions, toss these cards into a recipe box, and then review the contents of the recipe box ... reward myself with one after each paragraph that I succeed in writing.) ... direct, thorough, and helpful feedback as students develop as writers. I als

Writer: Gali Sree Kar Writer: Gali Sree Kar M.Sc, B ... -
It is used in glass and soap and paper industries. 2. It is also ...... Sometimes fruits like mango, banana, papaya, sapota and custard apple are often ripen by.

pdf writer for windows 98
Page 1. Whoops! There was a problem loading more pages. pdf writer for windows 98. pdf writer for windows 98. Open. Extract. Open with. Sign In. Main menu.

RAMON LLULL AS A VERNACULAR WRITER
scientific works in his maternal Catalan while, at the same time, he was deeply involved in the circulation of such works in other Romance .... Daytime telephone.

IT Practical Questions Writer
IT Practical Questions. Writer. Q1. Q2. Q3. Page 2. Q4. Q5. Page 3. Q6. Q7. Page 4. Q8. Q9. Page 5. Q10. Q11. Page 6. Q12. Calc. Q1. Page 7. Q2. Q3. Page 8 ...

Sparse-parametric writer identification using heterogeneous feature ...
The application domain precludes the use ... Forensic writer search is similar to Information ... simple nearest-neighbour search is a viable so- .... more, given that a vector of ranks will be denoted by ╔, assume the availability of a rank operat

2016.12.28 E-Commerce Product Writer English & Vietnamese.pdf ...
Please send your CV to [email protected]. Page 3 of 3. 2016.12.28 E-Commerce Product Writer English & Vietnamese.pdf. 2016.12.28 E-Commerce Product ...

PDF The Longman Writer Read online
The Longman Writer Download at => https://pdfkulonline13e1.blogspot.com/0321914139 The Longman Writer pdf download, The Longman Writer audiobook download, The Longman Writer read online, The Longman Writer epub, The Longman Writer pdf full ebook,