250+ TOP MCQs on Comparing Stubs, Mock Objects and In-container Testing and Answers

JUnit Questions and Answers for Aptitude Test on “Comparing Stubs, Mock Objects and In-container Testing”.

1. To implement a custom URL protocol handler, the URL method __________ is called.
a) setURLStreamHandlerFactory
b) setURLStreamFactory
c) setURLStreamHandlerFactorySetting
d) setStreamHandlerFactory
Answer: a
Clarification: A custom URLStreamHandlerFactory is passed to the setURLStreamHandlerFactory method.

2. _________ replace the objects with which the methods under test collaborate, offering a layer of isolation.
a) Classes
b) Mocks
c) Unified Stamps
d) Interfaces
Answer: b
Clarification: Mocks are similar to stubs because of the level of isolation they offer.

3. _____________ are empty shells that supply methods to let the tests have control of the behavior of all the business methods of the faked class.
a) Stubs
b) Jetty
c) Mocks
d) Interfaces
Answer: c
Clarification: Mocks are different from stubs in the sense that they do not implement any logic.

4. The most important point to consider when writing a mock is that it shouldn’t have any __________.
a) Redundancy
b) Abstraction
c) Matchers
d) Business Logic
Answer: d
Clarification: Mocks must be a dumb object that does only what the test tells it to do.

5. Applying the _________ pattern to a class means removing the creation of all object instances for which this class isn’t directly responsible and passing any needed instances instead.
a) Message Passing
b) Inversion Of Control
c) Observer Pattern
d) Strategy Pattern
Answer: b
Clarification: The instances may be passed using a specific constructor, using a setter, or as parameters of the methods needing them.

6. ____________ is an architectural pattern that stores in-memory object data in relational databases.
a) Active Record Pattern
b) Inversion Of Control
c) Observer Pattern
d) Strategy Pattern
Answer: a
Clarification: The active record pattern is an approach to accessing data in a database.

7. _____________ in computer science is a programming technique for converting data between incompatible type systems.
a) Active Record Pattern
b) Inversion Of Control
c) Object Relational Mapping
d) Strategy Pattern
Answer: c
Clarification: Object Relational Mapping creates, in effect, a “virtual object database”.

8. The ___________ is a software design pattern that allows the interface of an existing class to be used as another interface.
a) Adapter Pattern
b) Bridge Pattern
c) Decorator Pattern
d) Composite Pattern
Answer: a
Clarification: The Adapter design pattern allows otherwise incompatible classes to perform together by the conversion of the interface of one class into an interface expected by the clients.

9. The _______________ is a design pattern that adds behavior to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class.
a) Adapter Pattern
b) Bridge Pattern
c) Decorator Pattern
d) Composite Pattern
Answer: c
Clarification: The decorator pattern is often useful for adhering to the Single Responsibility Principle.

10. The ____________ is a design pattern in object-oriented programming that allows object composition to achieve the same code reuse as inheritance.
a) Adapter Pattern
b) Bridge Pattern
c) Decorator Pattern
d) Delegation Pattern
Answer: d
Clarification: In delegation, an object handles a request by delegating to a second object (the delegate).


JUnit for Aptitude Test,

Leave a Reply

Your email address will not be published. Required fields are marked *