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.
advertisement

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.

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.
advertisement

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.

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.

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.
advertisement

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

advertisement
advertisement
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