3
\$\begingroup\$

I recently started participating in code review site.

On my first question, the tag was inserted by an edit from a moderator, and soon yet another user suggested that I include a unit test.

Even though this might be a bit of a coincidence, I completely agree with the need of test cases when an algorithm is concerned.

I would like to suggest that we recommend a unit test be included with the tag, to prevent any code break.

I am suggesting an addition to code review help center or somewhere in UI.

Unless I have missed something, I think this might be a good addition.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Recommend it? Yes. Enforcing it? No. \$\endgroup\$ Aug 11, 2014 at 16:31

1 Answer 1

12
\$\begingroup\$

No.

While it is a good idea to use unit tests and it does prove to answerers that the code isn't broken to begin with, it would be impractical in practice. There is no technology to help us ensure that a unit test is included, so we would have to manually enforce this request. Also, it would exclude many beginners and enthusiasts who've never even heard of a unit test before.

But that doesn't help much...

No. It doesn't.

So what else could be done?

  • Edit the tag wiki and add a suggestion to include a unit test in algorithm questions.
  • Leave a comment on appropriate questions asking to see their unit test (if they have one).
  • Mention in your review the benefits of unit testing.
\$\endgroup\$
6
  • 1
    \$\begingroup\$ I agree. Plus, pointing out the value of the unit test as well as providing examples of unit testing are perfectly valid review points. Forcing a unit test to be included in the question would be like editing a question to fix the formatting rather than just talking about the formatting in an answer. \$\endgroup\$
    – nhgrif
    Aug 4, 2014 at 22:28
  • \$\begingroup\$ sorry if it was confusing, I was suggesting an addition to code review help center or somewhere in UI, not a functionality to the test if unit test exist \$\endgroup\$ Aug 4, 2014 at 22:30
  • 3
    \$\begingroup\$ we could edit it into the Tag Wiki that it would be beneficial to add a unit test because it is likely that one will be asked for \$\endgroup\$
    – Malachi Mod
    Aug 4, 2014 at 22:32
  • 1
    \$\begingroup\$ @Bhathiya-JaDogg-Perera: That may still not be something ideal to put into the Help Center. Plus, mods can only edit one of the pages, and it still doesn't quite belong there. Instead, a Meta post (such as this) can set the precedent. \$\endgroup\$
    – Jamal
    Aug 4, 2014 at 22:32
  • 2
    \$\begingroup\$ perhaps instead of a must, we should make it a gentle suggestion then. updated the question. \$\endgroup\$ Aug 4, 2014 at 22:34
  • 3
    \$\begingroup\$ I like @Malachi's suggestion, but I'm not sure how many people read the tag wikis. \$\endgroup\$
    – RubberDuck
    Aug 4, 2014 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .