Is it bad form to count on the order of your NUnit unit tests

后端 未结 8 1772
别跟我提以往
别跟我提以往 2021-02-13 06:16

I have been creating Unit tests like crazy and find that I\'m often having to set up something in one test that I just tore down in a previous test. Is it ever reasonable to cr

8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-13 06:43

    I would strongly advise to make all your unit tests independent.

    Your business logic / database structure etc. may change over time, so that you'll eventually have to replace or rewrite (or even discard) existing unit tests - and if you have several other tests depending on the one that you're replacing, this might cause unnecessary troubles because you'd have to go through all of the other tests as well and check if these are still working as expected.

    In addition, one failing unit test should not be able to drag many others (that might perfectly work on their own) down.

提交回复
热议问题