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
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
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
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
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
Explanation: AOSD seeks modularization of systems.
6. Custom JUnit rules can be created using ___________
a) TestRule Interface
b) CreateRule Interface
c) RuleCreate Interface
d) RuleInitialize Interface
View Answer
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
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
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
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
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.
- Buy Programming Books
- Buy JUnit Books
- Practice Programming MCQs
- Apply for JUnit Internship
- Apply for Information Technology Internship