Exams Attended

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

JUnit Interview Questions and Answers

Ques 16. How Do You Test a private Method?

When a method is declared as "private", it can only be accessed within the same class. So there is no way to test a "private" method of a target class from any test class.

To resolve this problem, you have to perform unit testing manually. Or you have to change your method from "private" to "protected".

Or if it is not possible to convert any of the above ways, you can test private method by using PowerMock partialMock.

Is it helpful? Add Comment View Comments
 

Ques 17. How Do You Test a protected Method?

As a method is declared as "protected", it can only be accessed within the same package where the class is defined. To test a "protected" method of a target class, you need to define your test class in the same package as the target class.

Is it helpful? Add Comment View Comments
 

Ques 18. How to create a Test Suite using JUnit in Eclipse?

There are four ways to create a JUnit test suite class in Eclipse with JUnit plugin: org.junit_3.8.1. First, select the directory (usually unit-tests) that you wish to create the test suite class in.

1. Select File > New > Other... > Java > JUnit > JUnit Test Suite.
2. Select the arrow of the button in the upper left of the toolbar. Select Other... > Java > JUnit > JUnit Test Suite,
3. Right click on a package in the Package Explorer view in the Java Perspective, and select Other... > Java > JUnit > JUnit Test Suite,
4. You can create a normal Java class as shown in the Eclipse tutorial, but include junit.framework.TestSuite as the super class of the test class you are creating.

Is it helpful? Add Comment View Comments
 

Ques 19. How To Create Test Class in Eclipse?

1. Select File ; New ; JUnit Test Case.
2. Select the arrow of the button in the upper left of the toolbar. Select JUnit Test Case.
3. Right click on a package in the Package Explorer view in the Java Perspective, and select JUnitTestCase.
4. Click on the arrow of the icon in the toolbar. Select JUnit Test Case.
5. You can create a normal Java class as shown in the Eclipse tutorial, but include junit.framework.TestCase as the super class of the test class you are creating.

Is it helpful? Add Comment View Comments
 

Ques 20. How Often Should You Run Your JUnit Tests?

You should run all your unit tests as often as possible, ideally every time the code is changed. Make sure all your unit tests always run at 100%. Frequent testing gives you confidence that your changes didn't break anything and generally lowers the stress of programming in the dark.

For larger systems, you may just run specific test suites that are relevant to the code you're working on. Run all your acceptance, integration, stress, and unit tests at least once per day.

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2021 WithoutBook