Primitive Unit Tests

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!

+5
source share
7 answers

. unit test . , , . , , , , , , , , , , . , , . , , , - , , IMO.

, , , , . , . , , . unit test, .

+5

. , . . , , , . , , , , . .

, , , , , .

+8

, , . 2 , , , , unit test - .

, /, .

+2

. , . , , . , . , .

+1

, , , , ..

, , , - , , (, ) . , - .

+1

, , . , , -, .

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.

0
source

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 ..."

0
source

All Articles