Without Book Interview Questions and Answers | Online Test | Moct Test
Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Institute Training Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

JUnit Interview Questions and Answers

Ques 16. Please Explain the Life Cycle of a JUnit 4.4 Test Class?

Ans. A JUnit 4.4 test class contains a @Before method, an @After method and multiple @test methods. When calling a test runner to run this test class, the runner will execute those methods in a specific order giving the test class an execution life cycle like this:

@Before
@Test XXX1
@After

@Before
@Test XXX2
@After

Is it helpful? Add Comment View Comments
Ques 17. How Do You Test a private Method?
Ans. 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 18. How Do You Test a protected Method?
Ans. 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 19. How to create a Test Suite using JUnit in Eclipse?
Ans. 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 20. How To Create Test Class in Eclipse?
Ans. 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

Most helpful rated by users:

©2017 WithoutBook