5

I recently upgraded some tests that unearthed a lot of previously hidden bugs. The bugs are rare and low priority, but they are still bugs and will eventually need to be fixed.

How should I handle the changes to the tests?

If I check-in my changes, many existing validations will fail, and given that these bugs are relatively low priority, they won't be fixed any time soon. The validations will have to be turned off until they get fixed. However, if we turn off so many validations, a larger regression may go unnoticed.

Another option is to check-in my changes but use error messages instead of validation failures. This clutters up the logs, and these bugs may go forgotten.

What are the best practices here?

2
  • 1
    If you check in the test with the failing validations turned off: is it any worse coverage than you currently have? Commented Oct 19, 2016 at 3:47
  • 1
    How does a larger regression go unnoticed based on already failing tests? They can't fail more.
    – JeffO
    Commented Oct 19, 2016 at 14:27

6 Answers 6

10

Am I stating the obvious?

The best practice, here, is: "Talk to Your Manager."

This check-in will have repercussions and you know it, it could scramble the workflow, people could decide to fix those bugs, and miss deadlines on features they were working on, maybe some of those bugs are really straightforward to fix, but some people's work will be diverted around this event.

There is some managing to do.

Also there may be parts of the bigger picture that are obscured from your sight and consequences you cannot foresee. (interdependencies/deadlines/contracts/versions and libraries that are already deployed in production)

If I was you manager I would appreciate your consideration before checking this in and would advise you on how to better handle it.

If you are the manager, I wonder why you're even asking.

2
  • It ought to be obvious, sadly it rarely is. Some serious thing has hit the fan, how serious and what to do is a management issue. How much else of your system isn't really tested either. How much technical debt has been incurred due to poor unit testing.
    – Bent
    Commented Oct 19, 2016 at 10:29
  • While I agree that you should communicate what you're doing to others on your team when your work could be disruptive (including to your manager), I think this answer passes the buck and does not really look at the pros/cons of making this type of change. "If you are the manager, I wonder why you're even asking"... because this is a difficult question that requires trading on a number of factors.
    – speedplane
    Commented Oct 20, 2016 at 23:38
6

nUnit has [Ignore] annotation. I would guess other testing frameworks have similar way to ignore test cases.

Any test runner then shows how many tests were ignored. So you can track how many tests are ignored and build some kind of "fix all/some ignored tests every week/sprint" policy.

2
  • 1
    This works provided the code eventually gets fixed. However, many times I have seen 100s of ignored tests. So there definitely needs to be an "ignore policy" in effect so tests don't end up in this dumping ground.
    – Jon Raynor
    Commented Oct 19, 2016 at 15:42
  • Yeah, ignored tests are a bad code smell, because the common cause is that a change broke a test and they didn't fix the code or the test, they just bypassed the test. Commented Dec 30, 2016 at 19:06
1

The best practice is not to change the tests unless you also plan to change the associated code for any bugs you find. If you were given the assignment and priority to change the tests, then spending a day or two fixing unearthed low priority bugs is, as Anakin would say, implied in your mandate.

If you've just inadvertently uncovered weeks of low-priority work, which is doubtful, then you need to put user stories on your backlog or issue tracker so the work isn't forgotten. Most test frameworks let you mark a test as ignored, so it is still present, but gets reported and counted as ignored so it doesn't get forgotten completely, and must at least be maintained to the point of compilability.

0

The bugs may be low priority but the brittle tests that fail because of these changes are a menace. Fix the tests now. Tests are meant to make refactoring easier not harder. Be careful not to simply write the next generation of brittle tests. Once they're fixed reevaluate how you feel about your "low priority" bugs.

Test's are not a silver bullet. You don't magically gain superior wisdom because you've written a test that seems to make sense. If the bugs you uncovered had obvious and easy fixes you wouldn't be asking you'd just fix them. You want it to be easy but it's not. Now you've got a failing test and you don't know what to do with it. I know three solutions here:

  • Fix the problem
  • Discard the test
  • Write a better test that makes the problem easier to fix

You've said something that I'm still waiting to make sense. Why would validations that rarely fail need to be turned off? Validation is supposed to catch bad input before it becomes state. That happening rarely isn't a reason to prefer rare bad state over rare validation errors.

I've no idea what problems you're referring to but the only thing I hate more than things that fail quietly are things that fail quietly only when they feel like it.

The only good reason I can think that this is tying you in knots is this is happening someplace that you don't have any good way to handle a validation error. If that's the problem you need to create one.

6
  • "Fix them now"... sorry, I'm a bit unclear. Fix the low priority bugs now? Or change the tests so that they do not fail due to the low priority bugs?
    – speedplane
    Commented Oct 19, 2016 at 2:25
  • The brittle tests. Commented Oct 19, 2016 at 2:29
  • @CandiedOrange, what brittle tests? Commented Oct 19, 2016 at 2:30
  • 1
    @CandiedOrange "Write tests that test what you want tested" - can't agree with that. So if I just write a simple bunch of tests I'm always green and everything's fine. Until one day it isn't. I favour pushing the boundary conditions in unit tests and this seems to be what OP has done here and he's found "Dragons". I get that the tests seem to be too monolithic and that you might be advocating breaking them up into small tests that test a very specific case but it's not clear from your answer.
    – mcottle
    Commented Oct 19, 2016 at 5:16
  • 2
    I think you've misunderstood the question, because while this is good advice in general, I don't see how it applies. The tests are finding actual bugs. The validations mentioned are not input validations, they are validations performed by OP's build tool to make sure that no tests are failing. If you "have no idea what problems [OP is] referring to", maybe don't try to fix them? Commented Oct 19, 2016 at 14:19
0

The rule should be that all tests should always succeed, and if they don't pass, bugs need to be fixed (taking into account that a unit test may have a bug and need fixing).

That said, if your team would be in trouble if you commit all your unit tests right now, they could be put on some branch, and whenever someone has time to work on it, they pick a few tests, run them, fix the bugs, and commit those tests with their fixes.

0

MSTest offers a TestCategory attribute. That is, you could mark those tests with

[TestMethod]
[TestCategory("WaitingBugs")]

During a "normal" build, you can exclude tests by category,

mstest.exe ... /category:"^!WaitingBugs"

True, one issue remains: someone needs to remember that there are some tests which are normally not run...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.