Explain the “setUp” and “tearDown” Python methods used in test cases

后端 未结 3 1983
一生所求
一生所求 2021-01-30 09:47

Can anyone explain the use of Python\'s setUp and tearDown methods while writing test cases apart from that setUp is called immediately be

3条回答
  •  孤独总比滥情好
    2021-01-30 10:29

    Suppose you have a suite with 10 tests. 8 of the tests share the same setup/teardown code. The other 2 don't.

    setup and teardown give you a nice way to refactor those 8 tests. Now what do you do with the other 2 tests? You'd move them to another testcase/suite. So using setup and teardown also helps give a natural way to break the tests into cases/suites

提交回复
热议问题