InterviewSolution
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. |
Which annotation must be used to define suite classes?(a) @RunWith(b) @SuiteClasses(c) @Suite(d) @SuiteClassI had been asked this question during an online exam.This question is from Running Parameterized Tests topic in section Exploring Core JUnit of JUnit |
|
Answer» Right answer is (B) @SuiteClasses |
|
| 2. |
When is the tearDown() method called in JUnit?(a) After all the tests have run(b) At the beginning of every test case(c) After each test case has run(d) At the beginning of the first test caseThis question was addressed to me in exam.My question is from Running Parameterized Tests topic in chapter Exploring Core JUnit of JUnit |
|
Answer» The correct OPTION is (C) After each TEST case has run |
|
| 3. |
JUnit test methods must compulsorily return what value?(a) String(b) int(c) Object(d) voidThis question was addressed to me in an interview for internship.The doubt is from Exploring Core JUnit topic in section Exploring Core JUnit of JUnit |
|
Answer» The correct OPTION is (d) void |
|
| 4. |
For a Suite class, the @RunWith annotation has the value of which class?(a) org.junit.runners.class(b) org.junit.Suite.class(c) org.runners.Suite.class(d) org.junit.runners.Suite.classThis question was addressed to me in homework.My question is from Composing Tests with a Suite in portion Exploring Core JUnit of JUnit |
|
Answer» RIGHT option is (d) org.junit.runners.SUITE.class Best EXPLANATION: “org.junit.runners.Suite.class” CONTAINS the definition for the Suite class and a the declaration is @RunWith(value=org.junit.runners.Suite.class). |
|
| 5. |
If we want to run test files Test1 and Test2 together, the @SuiteClasses annotation will be?(a) @SuiteClasses(value={Test1.class,Test2.class})(b) @SuiteClasses(value=All)(c) @SuiteClasses(Test1, Test2);(d) @SuiteClasses()This question was posed to me during a job interview.My question comes from Composing Tests with a Suite topic in chapter Exploring Core JUnit of JUnit |
|
Answer» Right ANSWER is (a) @SuiteClasses(VALUE={Test1.class,Test2.class}) |
|
| 6. |
Which annotation is used to list all the classes in a suite?(a) @RunWith(b) @SuiteClasses(c) @Classses(d) @SuiteClassThe question was asked in semester exam.The question is from Composing Tests with a Suite topic in portion Exploring Core JUnit of JUnit |
|
Answer» Right option is (B) @SuiteClasses |
|
| 7. |
The Suite object is a _____ that executes all of the @Test annotated methods in the test class.(a) Result(b) FolderConfigurationTest(c) FileConfigurationTest(d) RunnerThe question was posed to me during an interview.This intriguing question originated from Composing Tests with a Suite in division Exploring Core JUnit of JUnit |
|
Answer» The CORRECT answer is (d) Runner |
|
| 8. |
To run the file TestClass.class from the command line, we have to type what?(a) java TestClass(b) javac TestClass(c) java org.junit.runner.JUnitCore TestClass(d) org.junit.runner.JUnitCore TestClassI have been asked this question in class test.This interesting question is from JUnit Test Runners in chapter Exploring Core JUnit of JUnit |
|
Answer» RIGHT choice is (c) JAVA org.junit.runner.JUnitCore TestClass Explanation: The test CASES are EXECUTED using JUnitCore CLASS which is referenced by “org.junit.runner.JUnitCore”. |
|
| 9. |
What happens if the tester does not define a Suite?(a) The test runner automatically creates a Suite(b) Compilation Error(c) Every test fails(d) Every test passesThis question was addressed to me in an online quiz.Question is taken from Composing Tests with a Suite in portion Exploring Core JUnit of JUnit |
|
Answer» Correct choice is (a) The TEST runner automatically creates a Suite |
|
| 10. |
A parameterised test class must carry which annotation?(a) @Test(b) @ParameterisedClass(c) @Runwith(d) @ClassThis question was posed to me by my college professor while I was bunking the class.I'm obligated to ask this question of Running Parameterized Tests in section Exploring Core JUnit of JUnit |
|
Answer» Right CHOICE is (c) @Runwith |
|
| 11. |
The test class must carry the @RunWith annotation with the ______ class as its argument.(a) Default(b) Parameterised(c) Super(d) InheritedI got this question in an internship interview.This is a very interesting question from Running Parameterized Tests topic in portion Exploring Core JUnit of JUnit |
|
Answer» The CORRECT CHOICE is (b) Parameterised |
|
| 12. |
What is a test runner?(a) Used to execute the test file(b) Defines the test file(c) Used to write test cases(d) Used to define annotationsThe question was posed to me in quiz.Question is taken from Exploring Core JUnit in division Exploring Core JUnit of JUnit |
|
Answer» The correct option is (a) USED to EXECUTE the test file |
|
| 13. |
To listen to events during a test, which class has to be extended?(a) org.junit.runner.notification.RunListener(b) org.junit.runner.Listener(c) org.junit.runner.notification.Listener(d) org.junit.runner.RunListenerThe question was posed to me by my college professor while I was bunking the class.This interesting question is from JUnit Test Runners topic in portion Exploring Core JUnit of JUnit |
|
Answer» RIGHT option is (a) org.junit.runner.notification.RunListener The explanation is: To respond to events during a test RUN, RunListener is EXTENDED and the APPROPRIATE methods overridden. If a listener throws an exception during a test event, it is removed for the remainder of the test run. |
|
| 14. |
When does the wasSuccessful() method of the Runner class return true?(a) The test file compiled(b) The test file ran(c) Some of the test cases ran successfully(d) All the test cases ran succesfullyThe question was posed to me during a job interview.The doubt is from JUnit Test Runners in section Exploring Core JUnit of JUnit |
|
Answer» Right choice is (d) All the test cases ran succesfully |
|
| 15. |
How can a method be made to run before the execution of every test case?(a) Annotate the method with @Before(b) Prefix the method name with startfirst(c) Annotate the method with a @BeforeClass(d) Such a method cannot be madeI have been asked this question in an interview.My enquiry is from Running Parameterized Tests in portion Exploring Core JUnit of JUnit |
|
Answer» Correct OPTION is (a) Annotate the method with @Before |
|
| 16. |
JUnit test files are written in files with which file extension?(a) .junit(b) .test(c) .java(d) .unitI got this question by my school principal while I was bunking the class.Question is from Exploring Core JUnit topic in section Exploring Core JUnit of JUnit |
|
Answer» Correct option is (c) .java |
|
| 17. |
What are fixtures in JUnit?(a) Objects that specify when to run a test(b) Fixed state of a set of objects used as a baseline for running tests(c) Bundle of few test cases run together(d) Date objectsThis question was addressed to me in an international level competition.Origin of the question is Exploring Core JUnit in portion Exploring Core JUnit of JUnit |
|
Answer» CORRECT choice is (b) Fixed state of a set of objects used as a baseline for running tests For explanation I would say: Tests need to RUN against the BACKDROP of set of PREDEFINED or known objects. This set of objects is called a test FIXTURE. |
|
| 18. |
JUnit is used for what type of software testing for the Java language?(a) Unit Testing(b) Integration Testing(c) Functional Testing(d) System TestingI had been asked this question in exam.This interesting question is from Exploring Core JUnit in portion Exploring Core JUnit of JUnit |
|
Answer» Correct OPTION is (a) Unit Testing |
|
| 19. |
To create a custom test runner which class needs to be extended?(a) CustomRunner(b) TestRunner(c) Runner(d) UserRunnerI had been asked this question during an interview.I'm obligated to ask this question of JUnit Test Runners in section Exploring Core JUnit of JUnit |
|
Answer» Correct ANSWER is (c) RUNNER |
|
| 20. |
To start a test case as JUnit 3.8 test case which runner is required?(a) org.junit.runners.Junit4(b) org.junit.runners.Parameterized(c) org.junit.internal.runners.Junit38ClassRunner(d) org.junit.internal.runners.Junit4The question was asked in an interview for internship.This key question is from JUnit Test Runners in section Exploring Core JUnit of JUnit |
|
Answer» The correct choice is (C) org.junit.internal.runners.Junit38ClassRunner |
|
| 21. |
What does the fail() method do in JUnit?(a) Throws an assertion error unconditionally(b) Calls the default constructor(c) Outputs the message “Fail” to the console(d) Pauses the test for 1 secondI got this question in examination.My query is from Running Parameterized Tests in portion Exploring Core JUnit of JUnit |
|
Answer» CORRECT choice is (a) THROWS an ASSERTION error unconditionally To EXPLAIN I would say: The method throws an assertion error unconditionally. This might be helpful to show an incomplete test (maybe still being worked upon) or to ensure that an expected exception is thrown. |
|
| 22. |
A JUnit Unit Test Case is compulsorily characterised by a/an known _______ and a/an expected _____(a) output, input(b) input, output(c) variable, literal(d) program, variableI got this question during an interview.My question is taken from Exploring Core JUnit in division Exploring Core JUnit of JUnit |
|
Answer» Right option is (b) input, OUTPUT |
|
| 23. |
JUnit runners are available in which package?(a) org.junit.runners(b) junitfiles.runners(c) org.runners(d) org.junit.files.runnersI got this question in a job interview.This is a very interesting question from JUnit Test Runners in chapter Exploring Core JUnit of JUnit |
|
Answer» Right OPTION is (a) org.JUNIT.runners |
|
| 24. |
Suite class is the JUnit 4 equivalent of what feature of JUnit 3.8.x?(a) static Test suite() method(b) Test suite() method(c) static void suite() method(d) void suite() methodThis question was addressed to me in unit test.My question comes from Composing Tests with a Suite topic in chapter Exploring Core JUnit of JUnit |
|
Answer» Right choice is (a) static TEST suite() METHOD |
|
| 25. |
What does the getRunCount() method of the Result return?(a) String denoting the time of execution(b) Integer denoting the time of execution(c) int denoting the number of tests run(d) int denoting the number of failed testsThe question was asked in an online quiz.My question comes from JUnit Test Runners in section Exploring Core JUnit of JUnit |
|
Answer» Correct CHOICE is (c) int DENOTING the number of tests run |
|
| 26. |
Which annotation implies that a method is a JUnit test case?(a) @junit(b) @testcase(c) @org.Test(d) @org.junit.TestThe question was posed to me in an interview for internship.The doubt is from Exploring Core JUnit topic in section Exploring Core JUnit of JUnit |
|
Answer» RIGHT answer is (d) @org.JUNIT.Test To EXPLAIN: ANNOTATE a METHOD with @org.junit.Test to imply that it is a JUnit test case. |
|
| 27. |
JUnit Suites are independent of the capability of the ______ system.(a) Run(b) Class(c) Test(d) BuildThis question was posed to me in an international level competition.Question is from Composing Tests with a Suite topic in section Exploring Core JUnit of JUnit |
|
Answer» The correct ANSWER is (d) Build |
|
| 28. |
The ______ is a container used to gather tests for the purpose of grouping and invocation.(a) Result(b) TestCase(c) Suite(d) TestThe question was posed to me by my college professor while I was bunking the class.The query is from Composing Tests with a Suite topic in division Exploring Core JUnit of JUnit |
|
Answer» Correct option is (c) Suite |
|
| 29. |
What are Parameterised tests used for in JUnit?(a) Run a test many times with different sets of parameters(b) Run a test with no parameters(c) Run a test with only String parameters(d) Run a test once with fixed set of parametersThe question was asked during an internship interview.Question is from Running Parameterized Tests topic in section Exploring Core JUnit of JUnit |
|
Answer» Right OPTION is (a) Run a TEST many times with different sets of parameters |
|
| 30. |
What does the assertTrue(“message”,A) do?(a) Asserts that the condition A is true(b) Asserts that “message” = A(c) Asserts that A contains “message”(d) Asserts that the condition A is falseThe question was asked in an interview.Asked question is from Running Parameterized Tests in section Exploring Core JUnit of JUnit |
|
Answer» RIGHT ANSWER is (a) ASSERTS that the CONDITION A is true Explanation: assertTrue requires A to be a boolean expression and the “MESSAGE” is displayed. |
|
| 31. |
What is the purpose of assertArrayEquals(“message”, A, B)?(a) Checks that “message” is in both A and B(b) Checks that “message” is in A but not B(c) Checks that “message” is in B but not A(d) Asserts the equality of the A and B arraysThis question was addressed to me by my college professor while I was bunking the class.Origin of the question is Exploring Core JUnit in section Exploring Core JUnit of JUnit |
|
Answer» The correct choice is (d) ASSERTS the equality of the A and B arrays |
|
| 32. |
What type of object is returned on completion of a test?(a) org.junit.runner.Result(b) org.junit.runner.Complete(c) org.junit.runner.Outcome(d) org.junit.runner.ObjectThe question was asked during an interview for a job.Origin of the question is JUnit Test Runners topic in chapter Exploring Core JUnit of JUnit |
|
Answer» RIGHT option is (a) org.junit.runner.Result Explanation: An org.junit.runner.Result OBJECT COLLECTS and SUMMARIZES information from running multiple tests. |
|
| 33. |
To use JUnit in a project we need to add which JAR files on our test classpath?(a) junit.jar(b) hamcrest-core.jar(c) junit.jar and hamcrest-core.jar(d) java-junit.jarThis question was addressed to me in an interview for job.My question is from Exploring Core JUnit topic in section Exploring Core JUnit of JUnit |
|
Answer» RIGHT choice is (C) JUNIT.jar and hamcrest-core.jar Explanation: hamcrest-core.jar has Matchers that JUnit uses for UNIT testing. |
|