Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A student writes these names for test methods in a class that tests a Stack class. Say which names are good and which are bad, and why.
test1test_pop_gives_the_last_pushed_itemcheck_emptytest_pop_on_empty_raisestest_everythingHave you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. A test method must start with test to be found. Its name should say what it checks.
test1: it is found, but the name says nothing. Bad. When it fails, you do not know what broke.test_pop_gives_the_last_pushed_item: found, and clear. Good.check_empty: does not start with test, so unittest never runs it. Bad, and dangerous, because nobody notices.test_pop_on_empty_raises: found, and clear. Good.test_everything: found, but it tests too much at once. If it fails, you do not know which part. Bad.Answer: Good: 2 and 4. Bad: 1 (no meaning), 3 (never run), 5 (too much).
Log in to join the discussion.
Loading…