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

  • SEARCH
  • Home
  • 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 506k
  • Answers 506k
  • 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 Given HTML like this: ​<table> <tr><td/><td/></tr> <tr><td/><td/></tr> </table>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ for example… May 16, 2026 at 3:47 pm
  • Editorial Team
    Editorial Team added an answer Try this line ffmpeg -i video.flv -an -vcodec png -vframes… May 16, 2026 at 3:47 pm
  • Editorial Team
    Editorial Team added an answer I've logged a bug here: Pl go thru it and… May 16, 2026 at 3:47 pm

Trending Tags

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

Top Members

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
I think this is not really possible but worth asking anyway. Say I have
I've never used TDD and unit testing properly, but would like to learn some
A lot of code in a current project is directly related to displaying things
I've just finished reading Roy Osherove's The Art of Unit Testing and I am
I have been studying .NET 4.0 Code Contracts and looking on stackoverflow as well
Is there any way to (unit) test my own HtmlHelpers? In case when I'd
I primarily spend my time working on automated tests of win32 and .NET applications,
I'm strongly considering adding unit testing to an existing project that is in production.

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.