JUnit Questions and Answers – Putting Ant to The Task

«
»

This set of JUnit Assessment Questions and Answers focuses on “Putting Ant to The Task”.

1. The __________ interface allows setting expectations for an associated expected invocation.
a) IMocksControl
b) IExpectationSetters<T>
c) IExpectation<T>
d) Isetters<T>
View Answer

Answer: b
Explanation: The IexpectationSetters<T> interface is extended and allows setting expectation for the expected invocation.
advertisement

2. _____________ function expect the last invocation any times.
a) andStubReturn(T value)
b) andThrow(Throwable throwable)
c) anyTimes()
d) asStub()
View Answer

Answer: c
Explanation: anyTimes() returns IExpectationSetters<T> object to allow method call chaining.

3. ______________ sets stub behavior for the expected invocation.
a) andStubReturn(T value)
b) andThrow(Throwable throwable)
c) anyTimes()
d) asStub()
View Answer

Answer: d
Explanation: Setting the stub behavior is needed for void methods.

4. _______________ expect the last invocation between min and max times.
a) times(int count)
b) times(int min, int max)
c) once()
d) asStub()
View Answer

Answer: b
Explanation: The max and min values are passed as arguments in the function definition times(int min, int max).
advertisement

5. ____________ expect the last invocation a specified number of times.
a) times(int count)
b) times(int min, int max)
c) once()
d) asStub()
View Answer

Answer: a
Explanation: times (int count) specifies the number of times to expect the last invocation via the count argument.

6. _____________ sets a stub object that will be used for the calculation of the answer for the expected invocation.
a) andAnswer(IAnswer<? extends T>answer)
b) andDelegateTo(Object delegateTo)
c) andStubAnswer(IAnswer<? extends T> answer)
d) andThrow(Throwable throwable)
View Answer

Answer: c
Explanation: andStubAnswer(IAnswer<? extends T>answer) either returns a value, or throws an exception.

7. _______________ sets a stub object implementing the same interface as the mock.
a) andAnswer(IAnswer<? extends T> answer)
b) andDelegateTo(Object delegateTo)
c) andStubAnswer(IAnswer<? extends T> answer)
d) andStubDelegateTo(Object delegateTo)
View Answer

Answer: d
Explanation: The expected method call will be delegated to it with the actual arguments.
advertisement

8. _____________ records a call but returns nothing.
a) andVoid()
b) times(int min, int max)
c) once()
d) asStub()
View Answer

Answer: a
Explanation: andVoid() is used to chain calls on void methods expectLastCall(), andThrow(e), andVoid().

9. _____________ expects the last invocation once.
a) andVoid()
b) times(int min, int max)
c) once()
d) asStub()
View Answer

Answer: c
Explanation: This is the default in EasyMock.

10. _______________ sets a return value that will be returned for the expected invocation.
a) andReturn(T value)
b) times(int min, int max)
c) once()
d) asStub()
View Answer

Answer: a
Explanation: The andReturn( T value) take as an argument value, which is the value to return.

Sanfoundry Global Education & Learning Series – JUnit.
To practice all areas of JUnit Assessment Questions, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn