JUnit Questions and Answers – Comparing Stubs, Mock Objects and In-container Testing

This set of JUnit Questions and Answers for Aptitude Test focuses 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: c
Explanation: Mocks are different from stubs in the sense that they do not implement any logic.
advertisement
advertisement

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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: b
Explanation: The instances may be passed using a specific constructor, using a setter, or as parameters of the methods needing them.
Note: Join free Sanfoundry classes at Telegram or Youtube

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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: Object Relational Mapping creates, in effect, a “virtual object database”.
advertisement

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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: The decorator pattern is often useful for adhering to the Single Responsibility Principle.
advertisement

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
View Answer

Answer: d
Explanation: In delegation, an object handles a request by delegating to a second object (the delegate).

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

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.