Thursday, August 27, 2009

JUnit Myths




Thought it's not too late to write about JUnit, hence pen down on myths & misunderstanding of unit testing as a concept.

JUnit(Unit Testing) is a beautiful, simplistic framework to do unit testing of your software components. As the name states, breaking huge software problem into manageable pieces and test it in a "divide and conquer" fashion.

General myths,
  1. Project managers view of JUnit, as a single medicine to all their software problems.- Manager
  2. Project which is nearing 90% complete and deciding to write JUnit :) :) just because your management shouts on the quality.- Management
  3. Writing JUnit as my manager and tech leads force me to do so. - Developer
  4. Have 100+ Testcase, still i doubt my application breaks. - Quality Assitance
In my experience
  1. "Writing JUnit is simple, Write once and Run anywhere Unit Test case needs skill".
  2. "Write Code to make your JUnit pass" - TDD
  3. "Developer should write more JUnit Testcase than the code itself" - Test Coverage
Above are my experience in writing JUnit(Unit) Testcases for projects, unit testcase is a discipline than a task to a developer which managers, leads and developers must understand. In most of the projects, i have seen developers writing 100's of unit testcases none of them work in a different environment, different data set etc. The reason is simple not externalizing the dataset, not mocking network resource/queues/file system/database and so on.
Writing JUnit also means changes to the actual code, to be able to run on a testable mode otherwise the unit test will not be effective.

2 comments:

Satheesh said...

nice thought senthil, it helps better if u could share the snippets to mock queues and other network dependencies.

Thanks
Satheesh

Senthil Balakrishnan said...

Would definitely do so in future blogs.