How to start unit-test old and new code?

前端 未结 5 1954
谎友^
谎友^ 2021-02-05 09:43

I admit that I have almost none experience of unittesting. I did a try with DUnit a while ago but gave up because there was so many dependencies between classes in my applicatio

5条回答
  •  名媛妹妹
    2021-02-05 10:06

    Well, the challenge in unit testing is not the testing itself, but in writing testable code. If the code was written not thinking about testing, then you'll probably have a really hard time.

    Anyway, if you can refactor, do refactor to make it testable. Don't mix object creation with logic whenever possible (I don't know delphi, but there might be some dependency injection framework to help in this).

    This blog has lots of good insight about testing. Check this article for instance (my first suggestion was based on it).

    As for a suggestion, try testing the leaf nodes of your code first, those classes that don't depend on others. They should be easier to test, as they don't require mocks.

提交回复
热议问题