Question: Which methods cannot be tested by JUnit? Explain why the answer is correct and rest options are not. a) public methods b) private methods c)

Which methods cannot be tested by JUnit? Explain why the answer is correct and rest options are not.

a) public methods

b) private methods

c) protected methods

d) any method can be tested with Junit test

sol33:

JUnit is a testing framework for Java programming language that can be used to test different types of methods in Java classes. However, there are certain types of methods that cannot be tested by JUnit.

The answer is (b) private methods. JUnit can only test public methods in a Java class. Private methods are inaccessible from outside the class, including JUnit test cases. In order to test a private method, it must be changed to public, or tested indirectly through public methods that call it.

Therefore, options (a) public methods, (c) protected methods, and (d) any method can be tested with JUnit test are all correct as JUnit can test public and protected methods, as well as any method that can be accessed by a public or protected method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!