Pythonunittest
很好,但可能很难将单元测试添加到大型项目中。原因是单元测试与最小块的功能测试有关。
单元测试意味着使用许多相互分离的小测试。除了代码的测试部分之外,它们应该独立于任何东西。
当单元测试被添加到现有代码中时,通常只添加它来测试被证明会导致错误的孤立案例。添加的单元测试应使用未更正的功能编写以揭示错误。然后应该修复错误,以便单元测试通过。这是第一个极端——只对失败的代码添加单元测试。这是必须的。您应该始终为失败的代码添加单元测试,并且应该在修复错误之前执行此操作。
Now, it is a question how to add unit tests to the large project that did not use them. The quantity of code of unit tests may be comparable with the size of the project itself. This way the other extreme could be to add unit test to everything. However, this is too much work, and you usually have to reverse engineer your own code to find the building blocks to be tested.
I suggest to find the most important parts of the code and add unit tests to them.