JUnit Question:

Download Job Interview Questions and Answers PDF

When Should Unit Tests Should Be Written In Development Cycle?

JUnit Interview Question
JUnit Interview Question

Answer:

If you are a TDD (Test-Driven Development) believer, you should write unit test before writing the code. Test-first programming is practiced by only writing new code when an automated test is failing.

Good tests tell you how to best design the system for its intended use. They effectively communicate in an executable format how to use the software. They also prevent tendencies to over-build the system based on speculation. When all the tests pass, you know you're done!

Whenever a customer test fails or a bug is reported, first write the necessary unit test(s) to expose the bug(s), then fix them. This makes it almost impossible for that particular bug to resurface later.

Test-driven development is a lot more fun than writing tests after the code seems to be working. Give it a try!

Download JUnit Interview Questions And Answers PDF

Previous QuestionNext Question
How Do You Test a Method That Does not Return Anything?How Do You Launch a Debugger When a Test Fails?