Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

___________ traverses the meaning of the contained matchers.(a) not(b) or(c) allOf(d) andAllI got this question in a national level competition.This interesting question is from Hamcrest Matchers topic in section Mastering JUnit of JUnit

Answer»

Right choice is (a) not

For EXPLANATION I WOULD SAY: The not Hamcrest matcher is used to traverse the meaning of matchers CONTAINED in the argument.

2.

______ is used only to improve the readability of the statements.(a) anything(b) is(c) sameInstance(d) nullValueThis question was addressed to me in an interview.My question is taken from Hamcrest Matchers in portion Mastering JUnit of JUnit

Answer»

Right CHOICE is (B) is

The BEST explanation: The Is Hamcrest MATCHER does not add any more functionality other than improving READABILITY.

3.

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 exceptionI have been asked this question in exam.This interesting question is from Testing Exception Handling in section Mastering JUnit of JUnit

Answer»

Right CHOICE is (C) TEST the value of the message in the exception

The explanation: The ‘EXPECTED’ argument cannot check the value of the message passed in the exception.

4.

The _________ is a sequential or non-iterative design process, which is used in software development processes, in which progress is seen as flowing steadily downwards.(a) Waterfall Model(b) Iterative Model(c) Spiral Model(d) Big Bang ModelThe question was asked in an online quiz.My question comes from Testing the Controller Component topic in chapter Mastering JUnit of JUnit

Answer»

Right option is (a) Waterfall Model

The EXPLANATION is: In a waterfall model, each phase or part must be completed before the next phase can BEGIN and there is no OVERLAPPING between the PHASES.

5.

The package for the assertThat() function is?(a) org.hamcrest.CoreMatchers.assertThat(b) org.junit.Assert.assertThat(c) org.junit.JunitMatchers.assertThat(d) org.junit.hasItem.assertThatThe question was posed to me during an interview.Question is from Hamcrest Matchers in section Mastering JUnit of JUnit

Answer»

The correct option is (B) org.JUNIT.ASSERT.assertThat

Best explanation: The asserThat() function is a PART of the main JUnit core assert FUNCTIONS.

6.

Inversion of Control is used to increase __________ of the code.(a) Functionality(b) Cleanliness(c) Effectiveness(d) ModularityI had been asked this question in examination.Question is taken from The Controller Component topic in section Mastering JUnit of JUnit

Answer»

Correct option is (d) Modularity

The best I can explain: Inversion of CONTROL makes the code more EXTENSIBLE RESULTING in more modular code.

7.

_________ 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 InjectionsThe question was asked in final exam.This key question is from Testing Exception Handling topic in division Mastering JUnit of JUnit

Answer»

Correct choice is (c) ASPECT ORIENTED Programming

For explanation I WOULD say: Aspect Oriented Programming adds ADDITIONAL behaviour to existing code by separately which code is modified USING a cut-point specification.

8.

________ can be useful in adding additional functionality which applies to every test within a test class.(a) Copy(b) Rules(c) Exceptions(d) BoundariesThe question was asked in an internship interview.I need to ask this question from Testing Exception Handling in chapter Mastering JUnit of JUnit

Answer»

Correct CHOICE is (b) Rules

The EXPLANATION: JUnit rules INTERCEPT the test methods and give ADDITIONAL FUNCTIONALITY.

9.

The principle of “Hollywood Principle: Don’t call us, we’ll call you” is commonly known as _____________(a) Calling Principle(b) Control Call(c) Inversion of Control(d) No-Show PrincipleThis question was addressed to me during an interview.My question is taken from The Controller Component topic in portion Mastering JUnit of JUnit

Answer» CORRECT ANSWER is (c) INVERSION of Control

For explanation: Inversion of Control focuses on separating what to do from when to do.
10.

The instanceOf matcher is equivalent to ________(a) isCompatibleType(b) isCompatible(c) isInstance(d) isSameI got this question in an internship interview.My question is based upon Hamcrest Matchers topic in division Mastering JUnit of JUnit

Answer» RIGHT choice is (a) isCompatibleType

Easiest explanation: Match whether objects are of compatible type (are instances of ONE ANOTHER).
11.

________________ is a library that contains a lot of helpful matcher objects , ported in several languages.(a) Java(b) Pygame(c) AllenWake(d) HamcrestThe question was posed to me during an interview.Enquiry is from Hamcrest Matchers in portion Mastering JUnit of JUnit

Answer»

Correct ANSWER is (d) HAMCREST

To elaborate: Hamcrest is a library that contains a lot of helpful MATCHER objects (known also as constraints or predicates).

12.

An example of a web controller is __________(a) Apache Struts Framework(b) JUnit(c) Java(d) PhpI had been asked this question in an interview.My query is from The Controller Component topic in portion Mastering JUnit of JUnit

Answer»

The correct option is (a) APACHE Struts Framework

Easiest EXPLANATION: Apache Struts Framework is an OPEN source framework for BUILDING Servlet/JSP based web applications which is an example of a web CONTROLLER.

13.

________ checks to see if any of the contained matchers match.(a) anyOf(b) allOf(c) instanceOf(d) notNullThe question was asked during an interview.My question is taken from Hamcrest Matchers topic in portion Mastering JUnit of JUnit

Answer» CORRECT choice is (a) ANYOF

To explain I would say: The anyOf Hamcrest MATCHER is just like the || OPERATOR.
14.

To avoid overdesigning an interface, usually ____________ is used.(a) Agile Development(b) Test Driven Development(c) Base Design Development(d) Waterfall DevelopmentThe question was posed to me in class test.My question is taken from Testing the Controller Component topic in chapter Mastering JUnit of JUnit

Answer»

The correct OPTION is (b) Test Driven Development

The BEST I can explain: Since test driven development is RELIANT on a very short development cycle being REPEATED, it is USED to avoid overdesigning an interface.

15.

Which Hamcrest matcher is just like the && operator?(a) Is(b) Anything(c) sameInstance(d) allOfThe question was posed to me in an interview.The question is from Hamcrest Matchers in portion Mastering JUnit of JUnit

Answer»

The CORRECT option is (d) allOf

The explanation: CHECKS to SEE if all contained matchers MATCH (just LIKE the && operator).

16.

@Test(timeout = 130) implies a time limit of ___________(a) 130 milliseconds(b) 130 minutes(c) 130 seconds(d) 1.30 minutesI have been asked this question by my college director while I was bunking the class.This question is from Timeout Testing in portion Mastering JUnit of JUnit

Answer» RIGHT answer is (a) 130 MILLISECONDS

To explain I would say: The timeout argument is in milliseconds.
17.

To use Parameterized.class with the @RunWith annotation, we need to import __________(a) org.junit.runners.Parameterized(b) org.junit.Parameterized(c) org.junit.runners.Parameterized(d) org.runners.ParameterizedI had been asked this question in class test.My question comes from Testing the Controller Component topic in section Mastering JUnit of JUnit

Answer»

The CORRECT choice is (a) org.JUNIT.runners.Parameterized

For EXPLANATION: The Parameterized.class is a part of the RUNNER class of JUnit.

18.

What is the signature of the addHandler method of the Controller interface?(a) void addHandler(Request request, RequestHandler requestHandler)(b) void addHandler(RequestHandler requestHandler);(c) void addHandler(RequestHandler requestHandler);(d) void addHandler(Request request, Request requestHandler);I got this question in semester exam.This intriguing question originated from The Controller Component topic in division Mastering JUnit of JUnit

Answer»

The correct choice is (a) VOID addHandler(Request request, RequestHandler requestHandler)

Explanation: The addHandler method TAKES a Request and then a RequestHandler to HANDLE that request as parameters.

19.

What applies the same timeout to every test method of a class?(a) @Timeout(b) @Expected(c) Timeout Rule(d) Not possible to apply same timeoutI got this question by my college professor while I was bunking the class.Enquiry is from Timeout Testing in portion Mastering JUnit of JUnit

Answer»

The correct OPTION is (c) TIMEOUT Rule

To explain I WOULD SAY: The timeout can be specified as a rule so that it is applied to every method.

20.

Improving the design of existing code is known as __________(a) Refactoring(b) Improving(c) Betterment(d) UpgradingI had been asked this question in homework.Origin of the question is Testing the Controller Component in section Mastering JUnit of JUnit

Answer»

The CORRECT answer is (a) REFACTORING

Explanation: Refactoring is the PROCESS of restructuring existing CODE, changing the design.

21.

In what order is multiple @Before annotated methods run?(a) Oldest First(b) Newest First(c) Randomly(d) According to argument listThe question was asked during an interview.My doubt stems from Testing the Controller Component topic in portion Mastering JUnit of JUnit

Answer» CORRECT CHOICE is (c) Randomly

Explanation: It is not certain which @Before annotated METHOD will run first as all run randomly.
22.

Constructor-based DI is accomplished when the container invokes a class constructor with ____________(a) A number of arguments(b) No argument(c) Just one argument(d) Null objectsThe question was asked in examination.The query is from The Controller Component in division Mastering JUnit of JUnit

Answer»

Right OPTION is (a) A NUMBER of arguments

Easiest EXPLANATION: Each argument REPRESENTS a dependency on some other class.

23.

If a timeout which has been specified lapses before the completion of the test, its execution is interrupted with _____________(a) Interrupt()(b) Thread.interrupt()(c) Thread.interruptable()(d) Threads.interruptable()This question was posed to me in an internship interview.I need to ask this question from Timeout Testing topic in portion Mastering JUnit of JUnit

Answer» RIGHT option is (b) Thread.interrupt()

To explain: The TIMEOUT is brought about through Interruptible I/O and LOCKS.
24.

Timeout testing is ____________(a) Software Dependent(b) Hardware Dependent(c) Software and Hardware Dependent(d) Software and Hardware IndependentThe question was posed to me in an international level competition.Asked question is from Timeout Testing topic in chapter Mastering JUnit of JUnit

Answer»

The correct choice is (C) Software and HARDWARE Dependent

The best I can explain: Since different software and hardware GIVES different performance, TIMEOUT testing is software and hardware dependent.

25.

Controller logic component accesses the ________ logic component.(a) Class(b) Object(c) Business(d) CriteriaI had been asked this question by my school teacher while I was bunking the class.This interesting question is from Testing the Controller Component topic in section Mastering JUnit of JUnit

Answer»

Correct OPTION is (C) Business

For explanation I would say: Business logic COMPONENT is responsible for the business logic and delegates DATA ACCESS.

26.

Hamcrest is not a ______________ framework in itself.(a) Matching(b) Testing(c) Asserting(d) CheckingI had been asked this question in exam.Enquiry is from Hamcrest Matchers in portion Mastering JUnit of JUnit

Answer»

Correct option is (b) Testing

Easiest explanation: Hamcrest helps you declaratively SPECIFY simple MATCHING RULES.

27.

ExpectedException is found under which package?(a) org.junit.ExpectedException(b) org.junit.Test.ExpectedException(c) org.junit.Rule.ExpectedException(d) org.junit.rules.ExpectedExceptionThe question was posed to me by my college director while I was bunking the class.My question comes from Testing Exception Handling topic in section Mastering JUnit of JUnit

Answer»

The correct choice is (d) org.junit.rules.EXPECTEDEXCEPTION

To elaborate: ExpectedException is a RULE and HENCE, is founde INSIDE the rules package of JUnit.

28.

Constructor-based DI is preferred for ___________(a) Optional dependencies(b) Mandatory dependencies(c) All dependencies(d) No dependencyThe question was asked by my college professor while I was bunking the class.My question is from The Controller Component topic in chapter Mastering JUnit of JUnit

Answer»

The correct CHOICE is (B) Mandatory dependencies

The explanation is: Since there has to be at LEAST one ARGUMENT, Constructor-based DI is preferred for Mandatory dependencies.

29.

The Timeout Rule implements which interface?(a) Timeout(b) Test(c) TestingTimeout(d) TestRuleThe question was asked in an internship interview.This interesting question is from Timeout Testing topic in section Mastering JUnit of JUnit

Answer»

The CORRECT answer is (d) TestRule

Explanation: The TestRule INTERFACE is EXTENDED and implemented by Timeout Rule.

30.

What is timeout testing?(a) Testing for exceptions(b) Testing code execution within time limits(c) Testing code correctness(d) Testing code with time functionsThis question was posed to me in an interview for internship.Origin of the question is Timeout Testing topic in section Mastering JUnit of JUnit

Answer»

The CORRECT CHOICE is (b) TESTING code execution WITHIN time limits

Explanation: Timeout Testing checks if the code RUNS within specified time limits.

31.

When the container calls setter methods after invoking a constructor with no arguments it is known as ________________(a) Constructor-based dependency injection(b) Setter-based dependency injection(c) Setter-Seller dependency injection(d) No-Constructor dependency injectionI have been asked this question in an interview for internship.My question comes from The Controller Component topic in division Mastering JUnit of JUnit

Answer»

Right choice is (b) SETTER-based dependency injection

The explanation is: Setter-based DI is accomplished by the CONTAINER calling setter methods on your beans after INVOKING a no-argument constructor or no-argument static factory METHOD.

32.

The ______ is a component that “interacts with a client, controlling and managing the handling of each request”.(a) Master(b) RequestHandler(c) Controller(d) ClassI got this question during an internship interview.Enquiry is from The Controller Component topic in chapter Mastering JUnit of JUnit

Answer»

Right option is (c) Controller

Easiest EXPLANATION: A controller is a COMPONENT that “interacts with a CLIENT, CONTROLLING and managing the handling of each REQUEST,” and tells that it is used in both presentation-tier and business-tier patterns.

33.

Where is the Timeout class present?(a) org.junit.rules.Timeout(b) org.junit.Timeout(c) org.Timeout(d) org.junit.RuleClasses.TimeoutI had been asked this question in final exam.Question is from Timeout Testing topic in portion Mastering JUnit of JUnit

Answer»

Right CHOICE is (a) org.junit.rules.TIMEOUT

To elaborate: The correct package for the Timeout CLASS is under org.junit.rules.

34.

What are exceptions?(a) Anomalous conditions requiring special processing(b) Extra methods written to increase functionality(c) Commented lines describing exceptional cases(d) Null objectsI have been asked this question in an international level competition.Question is from Testing Exception Handling in chapter Mastering JUnit of JUnit

Answer»

Right answer is (a) Anomalous conditions requiring special processing

To EXPLAIN: Exceptions result in DISRUPTION of the NORMAL FLOW of the code execu

35.

What are the object(s) which make the core of the description of a controller component?(a) The Request, the Response(b) The Request, the Response, the RequestHandler, and the Controller(c) The Request(d) The RequestHandlerThe question was asked by my school principal while I was bunking the class.My question is taken from The Controller Component in division Mastering JUnit of JUnit

Answer»

The CORRECT option is (b) The Request, the RESPONSE, the RequestHandler, and the Controller

The best explanation: The flow of CONTROL is from the Request interface to the Response interface to the RequestHandler interface FINALLY to the Controller Interface.

36.

The _________ rule can be used to test both exception type and message.(a) Expected(b) ExpectedException(c) CatchException(d) CatchThe question was asked in an internship interview.I would like to ask this question from Testing Exception Handling topic in portion Mastering JUnit of JUnit

Answer» RIGHT ANSWER is (B) ExpectedException

For explanation: Since JUnit 4.7, ExpectedException can be used to TEST both exception type and message.
37.

Custom JUnit rules can be created using ___________(a) TestRule Interface(b) CreateRule Interface(c) RuleCreate Interface(d) RuleInitialize InterfaceThe question was asked during a job interview.My doubt stems from Testing Exception Handling topic in chapter Mastering JUnit of JUnit

Answer»

The correct answer is (a) TestRule Interface

Best explanation: JUNIT PROVIDE the TestRule Interface which HELPS define CUSTOM JUnit Rules.

38.

______________ Hamcrest matcher can be used to match absolutely everything.(a) Is(b) AnyOf(c) Anything(d) NotI have been asked this question in final exam.This is a very interesting question from Hamcrest Matchers topic in portion Mastering JUnit of JUnit

Answer» RIGHT OPTION is (c) Anything

For explanation I WOULD SAY: Matches ABSOLUTELY anything. Useful in some cases where one wants to make the assert statement more readable.
39.

AOP forms a basis for __________(a) Functional Development(b) Object Oriented Programming(c) Datafield Development(d) Aspect Oriented Software DevelopmentThe question was asked during an interview for a job.The origin of the question is Testing Exception Handling in section Mastering JUnit of JUnit

Answer»

The correct CHOICE is (d) Aspect Oriented Software Development

The EXPLANATION is: AOSD SEEKS MODULARIZATION of SYSTEMS.

40.

The ___________ method confirms that both references are to the same object.(a) assertEquals(b) assertEqual(c) assertEqualObject(d) assertSameThis question was posed to me by my school teacher while I was bunking the class.My doubt is from Testing the Controller Component topic in section Mastering JUnit of JUnit

Answer» RIGHT OPTION is (d) ASSERTSAME

Explanation: assertSame USES the == operator to compare OBJECTS.
41.

The equals() method is inherited from which base class?(a) Object(b) String(c) Integer(d) org.junit.EqualsThe question was posed to me in an interview for internship.The origin of the question is Testing the Controller Component in chapter Mastering JUnit of JUnit

Answer»

The correct option is (a) Object

Explanation: The EQUALS() METHOD is inherited from the Objects CLASS defined in java.lang.Object.

42.

A Timeout Rule is initialized by ____________(a) @Rule public Timeout object = new Timeout()(b) @Rulepublic Timeout object = Timeout.seconds()(c) public Timeout object = Timeout.seconds()(d) public Timeout object = new Timeout()This question was addressed to me in an online interview.This intriguing question originated from Timeout Testing topic in division Mastering JUnit of JUnit

Answer»

Correct option is (b) @Rulepublic TIMEOUT OBJECT = Timeout.seconds()

For explanation: The correct way to initialise a Timeout Rules is USING the Timeout.seconds() function.

43.

The ___________ parameter is used along with the @Test annotation to test for timeouts.(a) Expected(b) Timeout(c) NoLimit(d) TimeThe question was posed to me in an interview for internship.Query is from Timeout Testing topic in section Mastering JUnit of JUnit

Answer»

Correct answer is (b) Timeout

Easiest explanation: Timeout PARAMETER SPECIFIES the MAXIMUM time each TEST method can take.

44.

________ describes a class of functions which when run modify other functions.(a) Class(b) Advice(c) Modifiers(d) ChangersThe question was posed to me during an internship interview.My question is based upon Testing Exception Handling topic in chapter Mastering JUnit of JUnit

Answer»

Correct OPTION is (b) Advice

The EXPLANATION is: Advice is a certain method APPLIED at a certain join of a CODE.

45.

The assertEquals() method uses which underlying method to compare objects?(a) ==(b) equals()(c) isequal()(d) =I got this question in class test.My question is from Testing the Controller Component topic in section Mastering JUnit of JUnit

Answer»

The CORRECT OPTION is (b) equals()

For explanation I would say: The assertEquals() METHOD makes USE of equals() to compare objects, COMPARING identity.