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
a
created through refactor cycle (extract class) ofb
(happens while practicing tdd),a
should totally left untested! no need test @ all!
indeed, structure of code (in case, separation of classes/srp) should independent of unit concept;b
,a
in case belonging same unit.if
a
existed beforeb
,b
should not based on fact, ,b
's whole behavior should tested.
a
, b
not belonging same layer (distinct boundaries instance):
- if
b
gui class, ,a
business class,a
should doubled/mocked when testingb
, ,a
should have full test dedicated it.
indeed, domain architecture should not mingledbehavior/feature
notion.
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