JUnit Questions and Answers – JMock

This set of JUnit Multiple Choice Questions & Answers (MCQs) focuses on ” JMock”.

1. The Cobertura command for merging datafiles is ________________
a) cobertura-report.bat
b) cobertura-instrument.bat
c) cobertura-check.bat
d) cobertura-merge.bat
View Answer

Answer: d
Explanation: The cobertura-merge.bat command is used along with parameters to run merging using Cobertura.

2. In order to write testable code, ______________ should be reduced as much as possible.
a) Dependencies
b) Redundancies
c) Objects
d) Classes
View Answer

Answer: a
Explanation: Classes with too many dependencies require complicated tests.

3. A solution to reducing dependencies is to separate code between methods that instantiate new ____________ and methods that provide application logic.
a) Classes
b) Objects
c) Modules
d) Functions
View Answer

Answer: b
Explanation: Separation of objects and logic leads to reduced dependencies.
advertisement
advertisement

4. ________________ is a design guideline that states that one class should know only as much as it needs to know.
a) Law of knowledge
b) Class laws
c) Law of Demeter
d) Action methods
View Answer

Answer: c
Explanation: The law of demeter is also known as the Principle of Least Knowledge.

5. ____________ is a useful design pattern that ensures a class has only one instance.
a) Modular code
b) Lossless paradigm
c) Granular methods
d) Singleton
View Answer

Answer: d
Explanation: Most often, the implementation of a singleton defines a private constructor and a static variable.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. The obvious drawback of a singleton is that it introduces _____________ into the application.
a) Redundancies
b) Errors
c) Global State
d) Modules
View Answer

Answer: c
Explanation: The global state object can be accessed by anyone.

7. _______________ can easily be used to substitute application code with the test code.
a) Encapsulation
b) Polymorphism
c) Overloading
d) Static binding
View Answer

Answer: b
Explanation: Polymorphism is used to force certain code patterns to be tested.
advertisement

8. At runtime, code can’t change a/an ___________ hierarchy.
a) Encapsulation
b) Polymorphism
c) Overloading
d) Inheritence
View Answer

Answer: d
Explanation: As code cannot change the hierarchy, objects needs to be composed differently.

9. For wrtiting favourable tests, __________ is perferred over inheritance.
a) Encapsulation
b) Polymorphism
c) Overloading
d) Composition
View Answer

Answer: d
Explanation: Composition is a better code re-use mechanism.
advertisement

10. One of the main ways to decrease complexity is to try to avoid long _________ and if statements.
a) switch
b) then
c) default
d) static
View Answer

Answer: a
Explanation: Long switch statements increase the complexity of code and corresponding test cases.

Sanfoundry Global Education & Learning Series – JUnit.
To practice all areas of Junit, 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.