Have you ever added unit tests, after the fact, to legacy code? How complicated was code and how difficult to stub and mock everything? Was the end result worthwhile?
相关问题
- Dependencies while implementing Mocking in Junit4
- How to unit test a reactive component where ngCont
- Access for global variables JavaScript unit testin
- Googletest Parametrized tests crash
- Is there any means by which I could evaluate the t
相关文章
- How to replace file-access references for a module
- How to mock methods return object with deleted cop
- What is a good way of cleaning up after a unit tes
-
EF6 DbSet
returns null in Moq - React testing library: Test attribute / prop
- React/JestJS/Enzyme: How to test for ref function?
- python unit testing methods inside of classes
- Running into System.MissingMethodException: Method
Yes, and it's generally painful. I've often ended up having to write integration tests instead.
The book The Art of Unit Testing has some good advice on this. It also recommends the book Working Effectively with Legacy Code; I haven't read the latter yet, but it's on my stack.
EDIT: But yes, even minimal code coverage was worthwhile. It gave me confidence and a safety net for refactoring the code.
EDIT: I did read Working Effectively with Legacy Code, and it's excellent.
I've been speaking some time ago about idea of Reversed Tests Pyramid in Legacy Code at XPDays http://xpdays.com.ua/archive/xp-days-ukraine-2012/materials/legacy-code/
This presentation should answer the question why it is so important sometimes to start with integration/functional or even high level acceptance tests when working with legacy code. And then slowly, step by step introducing unit tests. There are no code examples - sorry, but you can find bunch of them in Michaels Feathers book "Working effectively with Legacy Code".
Also you can check Legacy Code Retreat http://www.jbrains.ca/legacy-code-retreat and look for that meeting in your area.