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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:29:11+00:00 2026-05-11T20:29:11+00:00

We have tried to introduce unit testing to our current project but it doesn’t

  • 0

We have tried to introduce unit testing to our current project but it doesn’t seem to be working. The extra code seems to have become a maintenance headache as when our internal Framework changes we have to go around and fix any unit tests that hang off it.

We have an abstract base class for unit testing our controllers that acts as a template calling into the child classes’ abstract method implementations i.e. Framework calls Initialize so our controller classes all have their own Initialize method.

I used to be an advocate of unit testing but it doesn’t seem to be working on our current project.

Can anyone help identify the problem and how we can make unit tests work for us rather than against us?

  • 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-11T20:29:11+00:00Added an answer on May 11, 2026 at 8:29 pm

    Tips:

    Avoid writing procedural code

    Tests can be a bear to maintain if they’re written against procedural-style code that relies heavily on global state or lies deep in the body of an ugly method.
    If you’re writing code in an OO language, use OO constructs effectively to reduce this.

    • Avoid global state if at all possible.
    • Avoid statics as they tend to ripple through your codebase and eventually cause things to be static that shouldn’t be. They also bloat your test context (see below).
    • Exploit polymorphism effectively to prevent excessive ifs and flags

    Find what changes, encapsulate it and separate it from what stays the same.

    There are choke points in code that change a lot more frequently than other pieces. Do this in your codebase and your tests will become more healthy.

    • Good encapsulation leads to good, loosely coupled designs.
    • Refactor and modularize.
    • Keep tests small and focused.

    The larger the context surrounding a test, the more difficult it will be to maintain.

    Do whatever you can to shrink tests and the surrounding context in which they are executed.

    • Use composed method refactoring to test smaller chunks of code.
    • Are you using a newer testing framework like TestNG or JUnit4?
      They allow you to remove duplication in tests by providing you with more fine-grained hooks into the test lifecycle.
    • Investigate using test doubles (mocks, fakes, stubs) to reduce the size of the test context.
    • Investigate the Test Data Builder pattern.

    Remove duplication from tests, but make sure they retain focus.

    You probably won’t be able to remove all duplication, but still try to remove it where it’s causing pain. Make sure you don’t remove so much duplication that someone can’t come in and tell what the test does at a glance. (See Paul Wheaton’s “Evil Unit Tests” article for an alternative explanation of the same concept.)

    • No one will want to fix a test if they can’t figure out what it’s doing.
    • Follow the Arrange, Act, Assert Pattern.
    • Use only one assertion per test.

    Test at the right level to what you’re trying to verify.

    Think about the complexity involved in a record-and-playback Selenium test and what could change under you versus testing a single method.

    • Isolate dependencies from one another.
    • Use dependency injection/inversion of control.
    • Use test doubles to initialize an object for testing, and make sure you’re testing single units of code in isolation.
    • Make sure you’re writing relevant tests
      • “Spring the Trap” by introducing a bug on purpose and make sure it gets caught by a test.
    • See also: Integration Tests Are A Scam

    Know when to use State Based vs Interaction Based Testing

    True unit tests need true isolation. Unit tests don’t hit a database or open sockets. Stop at mocking these interactions. Verify you talk to your collaborators correctly, not that the proper result from this method call was “42”.

    Demonstrate Test-Driving Code

    It’s up for debate whether or not a given team will take to test-driving all code, or writing “tests first” for every line of code. But should they write at least some tests first? Absolutely. There are scenarios in which test-first is undoubtedly the best way to approach a problem.

    • Try this exercise: TDD as if you meant it (Another Description)
    • See also: Test Driven Development and the Scientific Method

    Resources:

    • Test Driven by Lasse Koskela
    • Growing OO Software, Guided by Tests by Steve Freeman and Nat Pryce
    • Working Effectively with Legacy Code by Michael Feathers
    • Specification By Example by Gojko Adzic
    • Blogs to check out: Jay Fields, Andy Glover, Nat Pryce
    • As mentioned in other answers already:
      • XUnit Patterns
      • Test Smells
      • Google Testing Blog
      • “OO Design for Testability” by Miskov Hevery
    • “Evil Unit Tests” by Paul Wheaton
    • “Integration Tests Are A Scam” by J.B. Rainsberger
    • “The Economics of Software Design” by J.B. Rainsberger
    • “Test Driven Development and the Scientific Method” by Rick Mugridge
    • “TDD as if you Meant it” exercise originally by Keith Braithwaite, also workshopped by Gojko Adzic
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

We have tried to introduce unit testing to our current project but it doesn't
I'm duty-bound by policy to use CVS in this certain project, so even though
.NET 3.5, .NET 4.0, WPF, Silverlight, ASP.NET MVC - there's really a lot of
There is a need from a customer to log every data change to a
Since Flash 10 was introduced, many of the popular 'copy to clipboard' scripts out

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.