Every test pushes your code in a different direction. Write smaller test cases, instead of a single perfect one-size-fits-all test case.Choose the simplest set of inputs that exercise your code.Most tests can be reduced to: “given an input, expect this output.” Ideally a unit test is just 3-line long. Hide less important details from the user, so he can focus only on the important ones.Coders are afraid of changing code, so coders don’t add new tests. If the code mentions A, B, and C, don’t say B, C, and A in other places.ĭef unique ( elements ): tmp = for e in elements : tmp = None return tmp. With these two names GetSize() and ComputeSize(), we expect GetSize() to be a lightweight operation. For example, instead of disable_ssl = false, use use_ssl = true.ĭon’t create false expectation. For example, SpaceLeft() or HasSpaceLeft().Īvoid negated booleans. Use is, has, can, should, need as prefixes. For example, to find all events on a date, prefer PrintEventsInRange("OCT 16 12:00am", "OCT 17 12:00am") instead of PrintEventsInRange("OCT 16 12:00am", "OCT 16 11:59.999am").įor booleans variables, make clear what true or false means. Use Begin and End for inclusive/exclusive ranges. For example, print integer_range(first=2, last=4) to mean. What’s the result of print integer_range(start=2, stop=4)? Is it or ? Prefer First and Last. num_items () > MAX_ITEMS_IN_CART : Error ()
0 Comments
Leave a Reply. |