java - Should the testing interface always be identical to the functional interface? -


tdd newb here. know "test interface not implementation", might there case having "testing interface" of class x, using subclass mock , protected methods, superset of functional interface defined public methods of class x?

say have class this:

class indexmanager {     indexmanager( file file ){         ...     }      public void somefunctionalmethodusedbyotherclasses(){          ...     }  } 

in test class go this:

@runwith(mockitojunitrunner.class) public class indexmanagertest {     ...      class subclassmockindexmanager extends indexmanager {         subclassmockindexmanager( file file ){             super( file );         }          @override         protected indexwriterconfig createindexwriterconfig( analyzer analyser ){             return super.createindexwriterconfig( analyser );         }      }      @spy     @injectmocks     subclassmockindexmanager injectedspysm_indexmgr = new subclassmockindexmanager(tempfile); 

and make method in test "non-public interface" (aka "testing interface"):

@test public void whenindexismadeanindexwriterconfigshouldbecreated() throws exception {     injectedspysm_indexmgr.makeindexforfile();     verify( injectedspysm_indexmgr ).createindexwriterconfig(  mock(analyzer.class) ); } 

in response, turn red green, respond modifying app class follows:

class indexmanager {     indexmanager( file file ){         ...     }      // added part of normal red-green tdd development cycle     protected indexwriterconfig createindexwriterconfig( analyzer analyser ){         ... // make indexwriterconfig object          return indexwriterconfig;     }      public void somefunctionalmethodusedbyotherclasses(){          ...     }  } 

it's i'm puzzled why tdd development cycle should necessarily confined testing methods exposed other classes...

say have functiona , formed of functionb , functionc

it waste of time test both functionb & functionc, when can test end result ie functiona...as long functiona passes test there no need test others.

the functiona in example similar of testing interface.

or in laymen's terms: it's long water coming out of 'the end of pipe' exact expect there no need testing flow of water every 2 feets.

though still make decisions

edit

to avoid writing tests functionb & functionc it's best write test_functiona first , once it's green go there. test_functionb & test_functionc never needed. writing testfunctionc & testfuncionb make more difficult , make need write 3 tests.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -