Unit-testing with dependencies between tests

前端 未结 6 2057
日久生厌
日久生厌 2020-12-14 16:49

How do you do unit testing when you have

  • some general unit tests
  • more sophisticated tests checking edge cases, depending on the general ones
6条回答
  •  情歌与酒
    2020-12-14 17:01

    I have implemented a plugin for Nose (Python) which adds support for test dependencies and test prioritization.

    As mentioned in the other answers/comments this is often a bad idea, however there can be exceptions where you would want to do this (in my case it was performance for integration tests - with a huge overhead for getting into a testable state, minutes vs hours).

    You can find it here: nosedep.

    A minimal example is:

    def test_a:
      pass
    
    @depends(before=test_a)
    def test_b:
      pass
    

    To ensure that test_b is always run before test_a.

提交回复
热议问题