Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

____________ expect the last invocation a specified number of times.(a) times(int count)(b) times(int min, int max)(c) once()(d) asStub()The question was posed to me by my college professor while I was bunking the class.The query is from Putting Ant to The Task topic in chapter Running JUnit Tests from Ant of JUnit

Answer»

The CORRECT choice is (a) times(int COUNT)

For explanation I would SAY: times (int count) specifies the number of times to expect the last invocation via the count ARGUMENT.

2.

______________ integrates jMock with JUnit 3.(a) org.jmock(b) org.jmock.api(c) org.jmock.lib(d) org.jmock.integration.junit3I had been asked this question during an interview.I need to ask this question from Dependency Management with Ivy topic in division Running JUnit Tests from Ant of JUnit

Answer»

The correct choice is (d) org.jmock.integration.junit3

Easiest explanation: org.jmock.integration.junit4 is USED to INTEGRATE jMock with JUNIT 4.

3.

______________ sets stub behavior for the expected invocation.(a) andStubReturn(T value)(b) andThrow(Throwable throwable)(c) anyTimes()(d) asStub()This question was addressed to me in a national level competition.My question is based upon Putting Ant to The Task topic in chapter Running JUnit Tests from Ant of JUnit

Answer»

The CORRECT option is (d) asStub()

To ELABORATE: Setting the stub BEHAVIOR is NEEDED for void methods.

4.

____________ returns whether this executor is idle.(a) runUntilIdle(b) runPendingCommands(c) execute(d) isIdleThe question was posed to me by my school teacher while I was bunking the class.My question is based upon Creating HTML Reports in chapter Running JUnit Tests from Ant of JUnit

Answer» RIGHT ANSWER is (d) isIdle

The BEST I can explain: isIdle() function checks that there are no pending background tasks waiting to be RUN.
5.

______________ runs all commands that are currently pending.(a) runUntilIdle(b) runPendingCommands(c) execute(d) isIdleThis question was posed to me in an interview.The query is from Creating HTML Reports in chapter Running JUnit Tests from Ant of JUnit

Answer»

Correct answer is (b) runPendingCommands

The BEST explanation: If those commands ALSO schedule commands for EXECUTION, the SCHEDULED commands will not be EXECUTED.

6.

_____________ expects the last invocation once.(a) andVoid()(b) times(int min, int max)(c) once()(d) asStub()I got this question in unit test.I want to ask this question from Putting Ant to The Task in portion Running JUnit Tests from Ant of JUnit

Answer» CORRECT OPTION is (c) once()

Easiest explanation: This is the DEFAULT in EASYMOCK.
7.

NullPointerException is thrown if tasks or any of its elements are null.(a) True(b) FalseThis question was posed to me in unit test.My question is based upon Batching Tests in section Running JUnit Tests from Ant of JUnit

Answer»

Correct ANSWER is (a) True

The BEST I can explain: If any of the tasks or elements are NULL, the methods THROWS a NullPointerException.

8.

_____________ returns the expectation setter for the last expected invocation in the current thread.(a) createControl()(b) createControl(MockType type)(c) createNiceControl()(d) expect(T value)The question was posed to me in unit test.My doubt is from Ant Targets, Projects, Properties and Tasks topic in division Running JUnit Tests from Ant of JUnit

Answer» CORRECT answer is (d) expect(T VALUE)

The EXPLANATION: The PARAMETER value is used to transport the type to the ExpectationSetter.
9.

________________ creates a mock builder allowing to create a partial mock for the given class or interface.(a) createMockBuilder(Class toMock)(b) createMock(Class toMock)(c) createNiceControl()(d) createNiceMock(Class toMock)I got this question in my homework.I would like to ask this question from Ant Targets, Projects, Properties and Tasks in portion Running JUnit Tests from Ant of JUnit

Answer»

The CORRECT answer is (a) createMockBuilder(Class toMock)

To ELABORATE: createMockBuilder(Class toMock) is the OLD VERSION of partialMockBuilder(Class), which is more completion FRIENDLY.

10.

To use the createMock method of EasyMock we need to import ___________(a) org.easymock.EasyMock.createMock(b) org.EasyMock.createMock(c) org.easymock.createMock(d) org.createMockThe question was posed to me during an interview.My question is based upon Ant topic in section Running JUnit Tests from Ant of JUnit

Answer»

Correct option is (a) org.EASYMOCK.EasyMock.createMock

To ELABORATE: The EasyMock METHODS are FOUND under “org.easymock.EasyMock.*”.

11.

____________ runs executed commands until there are no commands pending execution.(a) runUntilIdle(b) runPendingCommands(c) execute(d) isIdleThe question was posed to me by my school principal while I was bunking the class.My doubt stems from Creating HTML Reports topic in chapter Running JUnit Tests from Ant of JUnit

Answer»

The CORRECT ANSWER is (a) runUntilIdle

Explanation: runUntilIdle does not tick time FORWARD but just RUNS executed COMMANDS.

12.

The _____________ exception can be thrown by the execute(Runnable command) function.(a) Arithmetic(b) ArrayIndexOutOfBounds(c) StringIndexOutOfBounds(d) RejectedExecutionExceptionThe question was asked in an interview for internship.Query is from Creating HTML Reports topic in division Running JUnit Tests from Ant of JUnit

Answer»

The correct answer is (d) REJECTEDEXECUTIONEXCEPTION

Explanation: RejectedExecutionException is thrown if the task cannot be ACCEPTED for EXECUTION.

13.

_______________ sets a stub object implementing the same interface as the mock.(a) andAnswer(IAnswer

Answer»

Right ANSWER is (d) andStubDelegateTo(OBJECT delegateTo)

The explanation is: The EXPECTED method call will be delegated to it with the actual ARGUMENTS.

14.

_______________ expect the last invocation between min and max times.(a) times(int count)(b) times(int min, int max)(c) once()(d) asStub()The question was posed to me in quiz.This question is from Putting Ant to The Task topic in division Running JUnit Tests from Ant of JUnit

Answer» CORRECT answer is (b) times(int min, int max)

The explanation is: The max and min values are passed as ARGUMENTS in the FUNCTION definition times(int min, int max).
15.

__________________ creates a mock object, of the requested type and name which are passed, which also has implementations of the given interface or extends the given class.(a) createMock(Class toMock)(b) createMock(MockType type, Class toMock)(c) createMock(String name, Class toMock)(d) createMock(String name, MockType type, Class toMock)This question was addressed to me in my homework.Question is from Ant topic in division Running JUnit Tests from Ant of JUnit

Answer» RIGHT option is (d) createMock(String name, MockType type, Class toMock)

To explain I would say: The name is PASSED as a parameter in the FUNCTION definition.
16.

When we’re talking about mock objects, a/an _________ is a feature built into the mock that verifies whether the external class calling this mock has the correct behavior.(a) Expectation(b) Explanation(c) Behavior(d) AmorousThe question was asked during an online interview.I'm obligated to ask this question of Ant in section Running JUnit Tests from Ant of JUnit

Answer»

The correct OPTION is (a) Expectation

Easy explanation: For example, a database connection MOCK could VERIFY that the close method on the connection is called exactly once during any test that involves code using this mock.

17.

______________ is a class that “blitzes” an object by calling it many times, from multiple threads.(a) Blitzer(b) DeterministicExecutor(c) DeterministicScheduler(d) SynchroniserThe question was asked in exam.The origin of the question is Dependency Management with Ivy in chapter Running JUnit Tests from Ant of JUnit

Answer»

The correct CHOICE is (a) BLITZER

The best explanation: The Blitzer class CALLS an object many times from different and MULTIPLE THREADS.

18.

Mocks are Trojan horses because they replace real ___________ from the inside, without the calling classes being aware of it.(a) Methods(b) Objects(c) Variables(d) ClassesThis question was posed to me in exam.This interesting question is from Ant in section Running JUnit Tests from Ant of JUnit

Answer»

The correct CHOICE is (b) Objects

To ELABORATE: Mocks have access to internal INFORMATION about the class, making them QUITE powerful.

19.

______________ executes the given tasks, returning the result of one that has completed successfully.(a) isShutdown(b) invokeAny(Collection

Answer»

The correct answer is (b) invokeAny(Collection extends Callable> tasks)

To EXPLAIN: UPON normal or exceptional RETURN, tasks that have not COMPLETED are CANCELLED.

20.

____________ submits a Runnable task for execution and returns a Future representing that task.(a) submit(Callable task)(b) awaitTermination(c) submit(Runnable task, T result)(d) invokeAll()This question was posed to me by my college director while I was bunking the class.This intriguing question comes from Batching Tests in portion Running JUnit Tests from Ant of JUnit

Answer»

Right OPTION is (C) submit(Runnable task, T RESULT)

To elaborate: The function TAKES as parameters the task to submit and the result to return.

21.

When a call to tick returns, the executor will be idle.(a) True(b) FalseThis question was addressed to me by my college professor while I was bunking the class.My enquiry is from Creating HTML Reports in chapter Running JUnit Tests from Ant of JUnit

Answer»

The CORRECT option is (a) True

Easiest EXPLANATION: Since the spawned BACKGROUND tasks are run the EXECUTOR remains IDLE.

22.

InterruptedException is thrownif any task cannot be scheduled for execution.(a) True(b) FalseI got this question in an interview.This key question is from Batching Tests in division Running JUnit Tests from Ant of JUnit

Answer»

The correct CHOICE is (b) False

To EXPLAIN: RejectedExecutionException is THROWN if any task cannot be scheduled for EXECUTION.

23.

_____________ exception is thrown while invokeAll() is interrupted while waiting.(a) InterruptedException(b) NullPointerException(c) RejectedExecutionException(d) ArrayIndexOutOfBoundsExceptionThis question was posed to me at a job interview.Query is from Batching Tests topic in section Running JUnit Tests from Ant of JUnit

Answer»

Right choice is (a) InterruptedException

Explanation: If the EXCEPTION is THROWN, the unfinished TASKS are CANCELLED.

24.

_____________ function expect the last invocation any times.(a) andStubReturn(T value)(b) andThrow(Throwable throwable)(c) anyTimes()(d) asStub()I have been asked this question during an online exam.I want to ask this question from Putting Ant to The Task in division Running JUnit Tests from Ant of JUnit

Answer»

Right ANSWER is (c) anyTimes()

The explanation is: anyTimes() returns IEXPECTATIONSETTERS OBJECT to allow METHOD call chaining.

25.

__________ method creates a mock object that implements the given interface, order checking is enabled by default.(a) createNiceControl(b) createMockBuilder(c) createNiceMock(d) createStrictMockThis question was addressed to me in an internship interview.Origin of the question is Ant topic in chapter Running JUnit Tests from Ant of JUnit

Answer»

The correct CHOICE is (d) CREATESTRICTMOCK

The best EXPLANATION: createStrictMock is the old version of strictMock(String, Class), which is more COMPLETION friendly.

26.

________________ contains classes to help test concurrent code with jMock.(a) org.jmock.concurrent(b) org.jmock.syntax(c) org.jmock.lib(d) org.jmock.integration.junit3This question was posed to me in examination.My question is based upon Dependency Management with Ivy topic in portion Running JUnit Tests from Ant of JUnit

Answer»

Right ANSWER is (a) org.jmock.concurrent

Best explanation: The classes defined under org.jmock.concurrent HELP TEST concurrent code with jMock.

27.

_______________ is used for the execution of the given tasks, returning a list of Futures holding their status and results after completion.(a) isShutdown(b) isTerminated(c) invokeAll(Collection

Answer»

Right option is (C) invokeAll(Collection extends Callable> tasks)

BEST explanation: Future.isDone() is true for each element of the returned LIST.

28.

____________ runs time forwards by a given duration, executing any commands scheduled for execution during that time period.(a) runUntilIdle(b) runPendingCommands(c) tick(d) isIdleThe question was asked in quiz.The query is from Creating HTML Reports topic in section Running JUnit Tests from Ant of JUnit

Answer»

The correct option is (C) TICK

Easiest explanation: The tick() COMMAND also runs any background TASKS SPAWNED by the scheduled tasks.

29.

The __________ interface allows setting expectations for an associated expected invocation.(a) IMocksControl(b) IExpectationSetters(c) IExpectation(d) IsettersI got this question during an online interview.Question is from Putting Ant to The Task in section Running JUnit Tests from Ant of JUnit

Answer»

Correct option is (b) IExpectationSetters

Easiest EXPLANATION: The IexpectationSetters INTERFACE is EXTENDED and ALLOWS setting expectation for the expected invocation.

30.

The ____________ interface is used in the creation of partial mocks with EasyMock.(a) IMockBuilder(b) IMocker(c) IBuilderexpect(T value)(d) MockBuilderThis question was posed to me in a national level competition.My doubt stems from Ant Targets, Projects, Properties and Tasks topic in chapter Running JUnit Tests from Ant of JUnit

Answer» RIGHT OPTION is (a) IMockBuilder

The explanation: The MockBuilder CLASS IMPLEMENTS the ImockBuilder interface.
31.

_____________ reports an argument matcher.(a) newCapture()(b) makeThreadSafe()(c) reportMatcher(IArgumentMatcher matcher)(d) createNiceMock(Class toMock)I got this question in homework.Query is from Ant Targets, Projects, Properties and Tasks topic in portion Running JUnit Tests from Ant of JUnit

Answer» CORRECT ANSWER is (c) reportMatcher(IArgumentMatcher MATCHER)

For explanation I would SAY: The reportMatcher method is USED to report an argument matcher.
32.

___________ is used for the creation of a mock object, with the specification of it being of the requested type, which has implementations of the given interface or extends the given class.(a) createMock(Class toMock)(b) createMock(MockType type, Class toMock)(c) createMock(String name, ClasstoMock)(d) createMock(String name, MockType type, ClasstoMock)The question was asked in an internship interview.This intriguing question comes from Ant in division Running JUnit Tests from Ant of JUnit

Answer»

Correct choice is (b) createMock(MockType type, CLASS toMock)

EASY explanation: createMock(MockType type, Class toMock) is the OLD version of MOCK(MockType, Class), which is more completion FRIENDLY.

33.

Other than RejectedExecutionException, the execute(Runnable command) function can also throw which exception?(a) Arithmetic(b) ArrayIndexOutOfBounds(c) StringIndexOutOfBounds(d) NullPointerExceptionI got this question during an interview.This key question is from Creating HTML Reports in chapter Running JUnit Tests from Ant of JUnit

Answer»

Right answer is (d) NullPointerException

Explanation: This EXCEPTION is THROWN if the COMMAND PASSED as argument is null.

34.

_____________ sets a stub object that will be used for the calculation of the answer for the expected invocation.(a) andAnswer(IAnswer

Answer»

Right CHOICE is (c) andStubAnswer(IANSWER extends T> ANSWER)

To explain I WOULD say: andStubAnswer(IAnswer extends T>answer) either returns a value, or throws an EXCEPTION.

35.

______________ is a ScheduledExecutorService that executes commands on the thread that calls runNextPendingCommand, runUntilIdle or tick.(a) Blitzer(b) DeterministicExecutor(c) DeterministicScheduler(d) SynchroniserThe question was posed to me by my school principal while I was bunking the class.This key question is from Dependency Management with Ivy in portion Running JUnit Tests from Ant of JUnit

Answer»

Right ANSWER is (a) Blitzer

Easy EXPLANATION: DeterministicScheduler EXECUTES on the thread CALLING runNextPendingCommand.

36.

______________ create a new capture instance that will keep only the last captured value.(a) newCapture()(b) makeThreadSafe()(c) createNiceControl()(d) createNiceMock(Class toMock)This question was addressed to me by my college professor while I was bunking the class.I want to ask this question from Ant Targets, Projects, Properties and Tasks in portion Running JUnit Tests from Ant of JUnit

Answer» CORRECT answer is (a) newCapture()

Explanation: The newCapture method without ARGUMENTS creates a new CAPTURE.
37.

anyObject() expects any double argument.(a) True(b) FalseThis question was posed to me in a national level competition.Asked question is from Ant Targets, Projects, Properties and Tasks in division Running JUnit Tests from Ant of JUnit

Answer»

Right ANSWER is (b) False

For EXPLANATION I would say: ANYOBJECT() expects any OBJECT argument.

38.

_____________ returns true if all tasks have completed following shut down.(a) submit(Callable task)(b) isTerminated(c) submit(Runnable task, T result)(d) invokeAll()The question was asked in final exam.Asked question is from Batching Tests topic in section Running JUnit Tests from Ant of JUnit

Answer»

The correct answer is (B) isTerminated

Explanation: isTerminated is NEVER true unless either shutdown or SHUTDOWNNOW was called first.

39.

________ submits a value-returning task for execution and returns a Future representing the pending results of the task.(a) submit(Callable task)(b) awaitTermination(c) submit(Runnable task, T result)(d) invokeAll()I have been asked this question in an online interview.My question comes from Batching Tests topic in portion Running JUnit Tests from Ant of JUnit

Answer»

Correct option is (a) submit(Callable TASK)

BEST explanation: The Future’s GET method will return the task’s result UPON successful COMPLETION.

40.

The Executor implementations provided implement ____________ which is a more extensive interface.(a) ExecutorService(b) ThreadPoolExecutor(c) ArrayDeque(d) SerialExecutorI have been asked this question in an international level competition.My query is from Creating HTML Reports topic in portion Running JUnit Tests from Ant of JUnit

Answer»

The CORRECT choice is (a) ExecutorService

The EXPLANATION: The ExecutorService interface is extended and IMPLEMENTED by the Executor implementations.

41.

_____________ expects a comparable argument greater than or equal the given value.(a) anyObject()(b) anyString()(c) geq(Comparable value)(d) anyDouble()This question was addressed to me during an online exam.The question is from Ant Targets, Projects, Properties and Tasks topic in chapter Running JUnit Tests from Ant of JUnit

Answer»

The correct choice is (c) GEQ(COMPARABLE VALUE)

The best EXPLANATION: geq stands for greater than or equal.

42.

______________ creates a mock object that implements the given interface with the specification is that order checking is disabled by default.(a) createMock(Class toMock)(b) createMock(MockType type, ClasstoMock)(c) createMock(String name, Class toMock)(d) createMock(String name, MockType type, Class toMock)The question was asked in exam.Asked question is from Ant topic in portion Running JUnit Tests from Ant of JUnit

Answer» CORRECT option is (c) createMock(STRING NAME, Class toMock)

Easiest EXPLANATION: The type PARAMETER is the interface that the mock object should implement.
43.

The __________ command executes the given command at some time in the future.(a) Execution()(b) execute(Runnable command)(c) scheduleNext()(d) poll()The question was posed to me during an internship interview.My query is from Creating HTML Reports topic in chapter Running JUnit Tests from Ant of JUnit

Answer»

Correct option is (B) EXECUTE(Runnable command)

The EXPLANATION is: The command may execute in a NEW THREAD, in a pooled thread, or in the calling thread.

44.

EasyMock instantiates an object based on an interface or class.(a) True(b) FalseThis question was addressed to me in examination.This question is from Ant in chapter Running JUnit Tests from Ant of JUnit

Answer»

Correct CHOICE is (a) True

Explanation: EasyMock is used to make mock objects which is BASED on the INTERFACE or CLASS being CALLED or extended.

45.

____________ creates a control of the requested type.(a) createControl()(b) createControl(MockType type)(c) createNiceControl()(d) createNiceMock(Class toMock)I have been asked this question by my school principal while I was bunking the class.This key question is from Ant Targets, Projects, Properties and Tasks topic in chapter Running JUnit Tests from Ant of JUnit

Answer» CORRECT answer is (B) createControl(MockType type)

Explanation: createControl(MockType type) RETURNS an ImocksControl OBJECT.
46.

__________ class is an Executor that executes commands on the thread that calls runPendingCommands or runUntilIdle.(a) Blitzer(b) DeterministicExecutor(c) DeterministicScheduler(d) SynchroniserI have been asked this question during an interview.Query is from Dependency Management with Ivy topic in chapter Running JUnit Tests from Ant of JUnit

Answer»

Correct answer is (B) DeterministicExecutor

The best explanation: The DeterministicExecutor executes COMMANDS on the THREAD calling RUNPENDINGCOMMANDS.

47.

_______________ contains implementations of the core interfaces that are used to adjust or extend jMock’s basic functionality.(a) org.jmock(b) org.jmock.api(c) org.jmock.lib(d) org.jmock.integration.junit3The question was asked in a national level competition.My query is from Dependency Management with Ivy topic in section Running JUnit Tests from Ant of JUnit

Answer» CORRECT answer is (C) org.jmock.lib

Explanation: The org.jmock.lib PACKAGE contains IMPLEMENTATIONS of the core interfaces.
48.

_____________ records a call but returns nothing.(a) andVoid()(b) times(int min, int max)(c) once()(d) asStub()I have been asked this question in an internship interview.My enquiry is from Putting Ant to The Task in section Running JUnit Tests from Ant of JUnit

Answer»

Right OPTION is (a) andVoid()

To elaborate: andVoid() is USED to CHAIN calls on void methods expectLastCall(), andThrow(E), andVoid().

49.

By default, a mock is thread safe.(a) True(b) FalseThe question was posed to me in class test.This intriguing question comes from Ant Targets, Projects, Properties and Tasks topic in section Running JUnit Tests from Ant of JUnit

Answer»

Correct ANSWER is (a) True

The explanation is: UNLESS NOT_THREAD_SAFE_BY_DEFAULT is set, a MOCK is THREAD SAFE.

50.

____________ Exception is thrown to report that a DeterministicScheduler has been asked to perform a blocking wait, which is not supported.(a) UnsupportedSynchronousOperationException(b) ArrayIndexOutOfBounds(c) StringIndexoutOfBounds(d) ArithmeticI got this question in exam.This is a very interesting question from Dependency Management with Ivy topic in division Running JUnit Tests from Ant of JUnit

Answer»

The correct choice is (a) UNSUPPORTEDSYNCHRONOUSOPERATIONEXCEPTION

The best explanation: UnsupportedSynchronousOperationException REPORTS that a DeterministicSchedular has been asked to perform a BLOCKING WAIT.