Unit-testing – How to write unit test cases

unit testing

Sometimes I end up writing unit test cases for code that other developers have written. There are occasions when I really don't know what the developer is trying to do (the business part) and I just manipulate the test case to get the green line. Are these things normal in the industry?

What is the normal trend? Are the developers supposed to write unit test cases for code they wrote themselves?

Best Answer

Try reading this blog post: Writing Great Unit Tests: Best and Worst Practices.

But there are countless others on the web.

In direct answer to your questions...

  1. "Normal trend" - I guess this could differ from place to place, whats normal for me might be odd for others.
  2. I would say (in my option) the developer who writes the code should write the test, ideally using methods like TDD, where you would write the test before the code. But others may have different methods and ideas here!

And the way you described of writing the tests (in your question) is totally wrong!!

Related Topic