JUnit Questions and Answers – Testing Exception Handling

This set of JUnit Multiple Choice Questions & Answers (MCQs) focuses on “Testing Exception Handling”.

1. What are exceptions?
a) Anomalous conditions requiring special processing
b) Extra methods written to increase functionality
c) Commented lines describing exceptional cases
d) Null objects
View Answer

Answer: a
Explanation: Exceptions result in disruption of the normal flow of the code execution

2. ________ can be useful in adding additional functionality which applies to every test within a test class.
a) Copy
b) Rules
c) Exceptions
d) Boundaries
View Answer

Answer: b
Explanation: JUnit rules intercept the test methods and give additional functionality.

3. _________ is a programming paradigm which allows the separation of cross cutting concerns, hence, increasing modularity.
a) Functional Programming
b) Object Oriented Programming
c) Aspect Oriented Programming
d) Data Injections
View Answer

Answer: c
Explanation: Aspect Oriented Programming adds additional behaviour to existing code by separately which code is modified using a cut-point specification.

4. ________ describes a class of functions which when run modify other functions.
a) Class
b) Advice
c) Modifiers
d) Changers
View Answer

Answer: b
Explanation: Advice is a certain method applied at a certain join of a code.

5. AOP forms a basis for __________
a) Functional Development
b) Object Oriented Programming
c) Datafield Development
d) Aspect Oriented Software Development
View Answer

Answer: d
Explanation: AOSD seeks modularization of systems.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Custom JUnit rules can be created using ___________
a) TestRule Interface
b) CreateRule Interface
c) RuleCreate Interface
d) RuleInitialize Interface
View Answer

Answer: a
Explanation: JUnit provide the TestRule Interface which helps define custom JUnit Rules.

7. With the ‘expected’ argument, one cannot ___________
a) Test a method
b) Test for exception type
c) Test the value of the message in the exception
d) Test for specific exception
View Answer

Answer: c
Explanation: The ‘expected’ argument cannot check the value of the message passed in the exception.

8. The _________ rule can be used to test both exception type and message.
a) Expected
b) ExpectedException
c) CatchException
d) Catch
View Answer

Answer: b
Explanation: Since JUnit 4.7, ExpectedException can be used to test both exception type and message.

9. ExpectedException is found under which package?
a) org.junit.ExpectedException
b) org.junit.Test.ExpectedException
c) org.junit.Rule.ExpectedException
d) org.junit.rules.ExpectedException
View Answer

Answer: d
Explanation: ExpectedException is a Rule and hence, is founde inside the rules package of JUnit.

10. The correct way to initialise an ExpectedException object is __________
a) public ExpectedException thrown = ExpectedException.none()
b) @Rule public ExpectedException thrown
c) @Rule public ExpectedException thrown = ExpectedException.none()
d) public ExpectedException thrown = ExpectedException.none()
View Answer

Answer: c
Explanation: The default value of no exception is assigned to the object during declaration.

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]

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.