JUnit Interview Questions and Answers
Download JUnit Interview eBook

Download Interview Questions And Answers PDF Download JUnit Interview Questions

JUnit Questions and Answers:

1 :: How Do You Launch a Debugger When a Test Fails?

Configure the debugger to catch the java.lang.AssertionError exception and suspend the execution.

Call the TestRunner to run the test under the debugger.

When the test fails again, The debugger will suspend the execution and start the debug mode.

Now you are ready to use debugger commands to find the code issue that causing the fail.

How you configure this depends on the debugger you prefer to use.
Most Java debuggers provide support to stop the program when a specific exception is raised.
Is This Answer Correct?    9 Yes 2 No
Place Your Answer

2 :: When Should Unit Tests Should Be Written In Development Cycle?

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!
Is This Answer Correct?    6 Yes 1 No
Place Your Answer

3 :: How Do You Test a Method That Does not Return Anything?

You need to follow the logic below to answer this question:

* 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 This Answer Correct?    8 Yes 1 No
Place Your Answer

4 :: When Objects Are Garbage Collected After a Test Is Executed?

My guess would be that all objects used in a test will be ready for Java garbage collector to release them immediately after the test has been executed.

By design, the tree of Test instances is built in one pass, then the tests are executed in a second pass. The test runner holds strong references to all Test instances for the duration of the test execution. This means that for a very long test run with many Test instances, none of the tests may be garbage collected until the end of the entire test run.

Therefore, if you allocate external or limited resources in a test, you are responsible for freeing those resources. Explicitly setting an object to null in the tearDown() method, for example, allows it to be garbage collected before the end of the entire test run.

If this is true, the JUnit runner should be improved to stop building all test instances before executing any tests. Instead, the JUnit runner should just take one test at a time, build an instance of this test, execute the test, and release the test when the execution is done.
Is This Answer Correct?    4 Yes 1 No
Place Your Answer

5 :: Do You Have To Write a Test for Everything?

No, just test everything that could reasonably break.

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 This Answer Correct?    4 Yes 1 No
Place Your Answer

Place Your Question



Top: JUnit Interview Questions and Answers
JUnit Interview Questions and Answers

Subscribe your email to receive free updates:

Enter your email address and get free job hunting tips, career advices, job vacancies, interview questions updates directly delivered to your email inbox




Top Frequently Asked JUnit Question
Frequently Asked JUnit Job Interview Question


Top Frequently opened Testing Job Interview categories
Most popular Testing Job Interview categories

Comments About JUnit Interview Questions and Answers

Share your valuable opinions, ideas and suggestions about JUnit Interview Questions and Answers
While placing your comment your email address is required but won't be published any where else; Personal information will be kept confidential; we do not sell or release our respective visitors private information.
  1. Webmaster 23rd of May 2013

    Webmaster Said

    Tell us what you feel about JUnit Interview Questions and Answers
    All comments will be published after review. No login or registration is required to post a comment on JUnit Interview Questions and Answers We offer and invite you to submit your valuable comment now; Please be respectful of others when commenting. Insulting others, self-promotional comments, website promotional comments, marketing stuff, SEO Techniques, SMS-style content and off-topic comments will not be approved at this information portal.
    So start sharing your thoughts regarding JUnit Interview Questions and Answers
    Thank you.

  2. Adim (1 Comment) 6th of August 2012

    Adim Said

    Please provide more JUNIT interview questions and provide a PDF to download JUNIT interview questions.
    Regards,
    Adim

Leave a Comment

Leave a Comment
  1.  Enter This Verification Code  Regenerate Verification Code  



Your reply will be added to the comment above (Below any other replies to this comment) -

Top Comments About: JUnit Interview Questions and Answers
Comments on JUnit Interview Questions and Answers

 
Top of Link back to JUnit Interview Questions and Answers
Link back to JUnit Interview Questions and Answers
 
Subscribe | Directory | Forum | Blog