java - Does it make sense to Unittest wrapper methods -


this question philosophical. given have method this:

public list<string> getstuffbyname(@notnull string name) throws someexception {         return somedependency.createquery().byname(name).list().stream()                 .map(execution -> execution.getprocessinstanceid())                 .collect(collectors.tolist()); } 

basically call dependencies method , process using stream api.

a unittest - in strict understanding(?) - testing 1 isolated unit. mock dependencies, assume tested units themselves.

if go through this, end method exclusively consists of stuff tested elsewhere.

eg jmockit test this:

public void test_get_processes_for_bkey_2(@mocked executionquery query,                                               @mocked list<string> processes,                                               @mocked list<execution> executions,                                               @mocked stream<execution> e_stream,                                               @mocked stream<string> pid_stream,                                               @mocked stream<string> pdef_stream      ) {     new expectations() {         {             somedependency.createquery(); result = query;             query.byname("somefilter"); result = query;             query.list(); result = executions;             executions.stream(); result = e_stream;             e_stream.map((function) any); result = fin_stream;             fin_stream.collect((collector) any); result = processes;             processes.size(); result = 2;         }     };      assertequals(tested.getstuffbyname("somefilter").size(), 2); } 

but test tell me?

in test-driven-development, omit tests of such "wrapper" methods?

what professional approach test be, independent of jmockit or other frameworks?

a "professional approach" test not mock anything. test should realistic can make it, while keeping sufficiently fast , stable.

unit tests (in pure/strict sense, unit isolated dependencies through mocking) overrated. isn't me saying it; authors kent beck (the main "creator" of tdd) , martin fowler no fans of "pure" unit testing either (see is tdd dead?, example).

mocking best used in exceptional cases, practical reasons can't write test without it. in own experience, integration tests (with no or minimal mocking) have proved better.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -