Related differences

Ques 21. Do You Have To Write a Test for Everything?

No, just test everything that could reasonably break. Keep in mind NullPointerException which occurs maximum.

Be practical and maximize your testing investment. Remember that investments in testing are equal investments in design. If defects aren't being reported and your design responds well to change, then you're probably testing enough. If you're spending a lot of time fixing defects and your design is difficult to grow, you should write more tests.

If something is difficult to test, it's usually an opportunity for a design improvement. Look to improve the design so that it's easier to test, and by doing so a better design will usually emerge.

Is it helpful? Add Comment View Comments
 

Ques 22. How Do You Test a Method That Does not Return Anything?

You need to follow the below logics:

* If a method is not returning anything through the "return" statement (void method), it may return data through its arguments. In this case, you can test the data returned in any argument.
* Else if a method is not returning any data through its arguments, it may change values of its instance variables. In this case, you can test changes of any instance variables.
* Else if a method is not changing any instance variable, it may change values of its class variables. In this case, you can test changes of any class variables.
* Else if a method is not changing any class variable, it may change external resources. In this case, you can test changes of any external resources.
* Else if a method is not changing any external resources, it may just doing nothing but holding the thread in a waiting status. In this case, you can test this waiting condition.
* Else if a method is not holding the thread in waiting status, then this method is really doing nothing. In this case, there is no need to test this method!

Is it helpful? Add Comment View Comments
 

Ques 23. When Should Unit Tests Should Be Written In Development Cycle?

You should write unit test before writing the code if you are a TDD (Test-Driven Development) believer. 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 gaining momentum these days compared to writing tests after the code.

Is it helpful? Add Comment View Comments
 

Ques 24. What is JUnit?

JUnit is a software testing framework for unit testing, open Source Software maintained by the JUnit.org community. JUnit was originally written by Erich Gamma and Kent Beck.

► Test runners for running tests
► Test fixtures for sharing common test data
► Assertions for testing expected results

Is it helpful? Add Comment View Comments
 

Most helpful rated by users: