Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 536681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:50:51+00:00 2026-05-13T09:50:51+00:00

Is it worth to write unit-tests for such the simple code: public class TableController

  • 0

Is it worth to write unit-tests for such the simple code:

public class TableController {
  private TableView view;

  public TableController(TableView view) {
    this.view = view;
  }

  public void onShowTable() {
    view.showTable();
  }
}

I have a lot of such very simple code in my projects which connects controllers, views, services, remote services, etc. Unit-tests just repeat everything and are usually larger 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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:50:51+00:00Added an answer on May 13, 2026 at 9:50 am

    No. You don’t have to unit test everything. On the other hand, you might want to try reversing the process and writing the tests first, then the code. In many cases you will find that if you write the test first, you end up writing different code that you thought you would as you’re thinking about it from the perspective of what should be the outcome when you write the test rather than what code should I write. When writing tests in this fashion you’ll find that the tests have much more value than simply exercising the code with them. Once you get the hang of it, you’ll also get a feel for when you need the test and when you don’t — automatic property accessors, for instance, don’t need to be unit tested IMO.

    If you’re already doing the tests first, then I’m not sure I understand the question since your tests can’t repeat something that hasn’t been written yet. You’ve used your tests to define what the methods should do. That’s a very useful activity and also protective in the event that other tests cause a breaking change. Much better to find it in a unit test than in a live application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 298k
  • Answers 298k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This page shows what the differences are between firefox/ie/ie8 are… May 13, 2026 at 7:31 pm
  • Editorial Team
    Editorial Team added an answer The connection string was indeed OK. The problem was that… May 13, 2026 at 7:31 pm
  • Editorial Team
    Editorial Team added an answer I think that what you want to do is use… May 13, 2026 at 7:31 pm

Related Questions

It's pretty clearly worth it to write tests for stuff that happens on the
My company is fairly new to unit testing our code. I've been reading about
Is there any way to (unit) test my own HtmlHelpers? In case when I'd
I'm developing a small TCP server, which will process some TCP packets and behave
On the SO blog and podcast Joel and Jeff have been discussing the, often

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.