java - Should I write tests for class A if it's covered from class B -
i'd opinion testing methodology.
lets assume have class , b. class b uses functionality of class a. b class tested , test coverage applied indirectly class a.
should write full tests directly class a? or should test not tested class functionality?
i asking because maybe in future there possibility b class removed or modified in way might not use same functionality class might leave methods untested. do?
classes != units
if practice tdd, understand behind.
imo, should test b's behavior without based on fact a tested.
actually, there 3 cases:
a , b belonging same layer:
if
acreated through refactor cycle (extract class) ofb(happens while practicing tdd),ashould totally left untested! no need test @ all!
indeed, structure of code (in case, separation of classes/srp) should independent of unit concept;b,ain case belonging same unit.if
aexisted beforeb,bshould not based on fact, ,b's whole behavior should tested.
a , b not belonging same layer (distinct boundaries instance):
- if
bgui class, ,abusiness class,ashould doubled/mocked when testingb, ,ashould have full test dedicated it.
indeed, domain architecture should not mingledbehavior/featurenotion.
to understand why, read recent article of uncle bob dealing concept:
excerpt of it:
it common misconception design of tests must mirror design of production code. tdd not require, author suggests, "that every unit in system paired well-designed [...] unit test." indeed, that's 1 of reasons many of have stopped calling them "unit" tests.
note: tdd doesn't care "future", in contrary, helps write code need, no more. therefore should not worry this:
in future there possibility b class removed or modified
if wrote tests (i prefer word "specs"), such removal detected immediately.
Comments
Post a Comment