SOLID and unit testing. Using language provided methods/classes -
so i've read thing called solid (mixed with) writing testable code. , d part. how 1 follow these guidelines when using primitive types or methods/classes provided language library.
does 1 need use dependency injection arrays (java (new int[64]
) or class members of say, filewriter?. these need injected using di or can class still instantiate them?
how far should go following above guidelines?
i not looking language-specific answer (if possible). imho answer should apply to, ex, php, python java, heck, c
you don't inject primitives or dto/pojo-like objects. reason are:
- simple value holders without business/domain logic associated
- easily stubbed without tools (creating array of fake data test not problematic)
filewriter
different it's in exact opposition points above. can't stub in test , make work without few strong assumptions - like, assume every future developer running code have file on machine. no-go unit tests , 1 of reasons why di applied in cases.
those problems come fact filewriter
serves communication point between 2 unrelated components - application , file system. class doing kind of integration (between app , db/network/file/rest etc.) in cases should abstracted , injected.
Comments
Post a Comment