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 1038681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:00:20+00:00 2026-05-16T15:00:20+00:00

I’ve been writing tests for a while now and I’m starting to get the

  • 0

I’ve been writing tests for a while now and I’m starting to get the hang of things. But I’ve got some questions concerning how much test coverage is really necessary. The consensus seems pretty clear: more coverage is always better. But, from a beginner’s perspective at least, I wonder if this is really true.

Take this totally vanilla controller action for example:

def create
  @event = Event.new(params[:event])
  if @event.save
    flash[:notice] = "Event successfully created."
    redirect_to events_path
  else
    render :action => 'new'
  end
end

Just the generated scaffolding. We’re not doing anything unusual here. Why is it important to write controller tests for this action? After all, we didn’t even write the code – the generator did the work for us. Unless there’s a bug in rails, this code should be fine. It seems like testing this action is not all too different from testing, say, collection_select – and we wouldn’t do that. Furthermore, assuming we’re using cucumber, we should already have the basics covered (e.g. where it redirects).

The same could even be said for simple model methods. For example:

def full_name
  "#{first_name} #{last_name}"
end

Do we really need to write tests for such simple methods? If there’s a syntax error, you’ll catch it on page refresh. Likewise, cucumber would catch this so long as your features hit any page that called the full_name method. Obviously, we shouldn’t be relying on cucumber for anything too complex. But does full_name really need a unit test?

You might say that because the code is simple the test will also be simple. So you might as well write a test since it’s only going to take a minute. But it seems that writing essentially worthless tests can do more harm than good. For example, they clutter up your specs making it more difficult to focus on the complex tests that actually matter. Also, they take time to run (although probably not much).

But, like I said, I’m hardly an expert tester. I’m not necessarily advocating less test coverage. Rather, I’m looking for some expert advice. Is there actually a good reason to be writing such simple tests?

  • 1 1 Answer
  • 1 View
  • 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-16T15:00:21+00:00Added an answer on May 16, 2026 at 3:00 pm

    My experience in this is that you shouldn’t waste your time writing tests for code that is trivial, unless you have a lot of complex stuff riding on the correctness of that triviality. I, for one, think that testing stuff like getters and setters is a total waste of time, but I’m sure that there’ll be more than one coverage junkie out there who’ll be willing to oppose me on this.

    For me tests facilitate three things:

    1. They garantuee unbroken old functionality If I can check that
      nothing new that I put in has broken
      my old things by running tests, it’s
      a good thing.

    2. They make me feel secure when I rewrite old stuff The code I
      refactor is very rarely the trivial
      one. If, however, I want to refactor
      untrivial code, having tests to
      ensure that my refactorings have not
      broken any behavior is a must.

    3. They are the documentation of my work Untrivial code needs to be
      documented. If, however, you agree
      with me that comments in code is the
      work of the devil, having clear and
      concise unit tests that make you
      understand what the correct behavior
      of something is, is (again) a must.

    Anything I’m sure I won’t break, or that I feel is unnessecary to document, I simply don’t waste time testing. Your generated controllers and model methods, then, I would say are all fine even without unit tests.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.