Should I write block tests for such simple code:
public class TableController { private TableView view; public TableController(TableView view) { this.view = view; } public void onShowTable() { view.showTable(); } }
My projects have very simple code that connects controllers, views, services, remote services, etc. Unit tests simply repeat everything and usually more than the code itself:
public class TableControllerTest { @Test public void showTable() { TableView view = createMock(TableView.class); view.showTable(); replayAll(); TableController controller = new TableController(view); controller.onShowTable(); verifyAll(); } }
Are such tests really needed?
Thanks!
. unit test . , , . , , , , , , , , , , . , , . , , , - , , IMO.
, , , , . , . , , . unit test, .
. , . . , , , . , , , , . .
, , , , , .
, , . 2 , , , , unit test - .
, /, .
. , . , , . , . , .
, , , , ..
, , , - , , (, ) . , - .
, , . , , -, .
In your specific case, however, I think that the functionality of these bits of code is too small to benefit from the tests and tests that they will use showTable, etc.
showTable
I would not test simple delegation methods.
There is a good saying (although I can’t remember where it came from): "Never check things that are too easy to break ..."