Sail E0 Webinar

MCQs

Total Questions : 10
Question 1. The Suite object is a _____ that executes all of the @Test annotated methods in the test class.
  1.    Result
  2.    FolderConfigurationTest
  3.    FileConfigurationTest
  4.    Runner
 Discuss Question
Answer: Option D. -> Runner


Suite is under org.junit.runners.Suite, Suite objects are Runners.


Question 2. JUnit Suites are independent of the capability of the ______ system.
  1.    Run
  2.    Class
  3.    Test
  4.    Build
 Discuss Question
Answer: Option D. -> Build


JUnit Suites are useful to organize tests in Java, independent of the capability of the build system, because it's common for someone or a group other than the developers to maintain builds.


Question 3. What is the purpose of assertArrayEquals("message, A, B)?
  1.    Checks that message" is in both A and B
  2.    Checks that message" is in A but not B
  3.    Checks that message" is in B but not A
  4.    Asserts the equality of the A and B arrays
 Discuss Question
Answer: Option D. -> Asserts the equality of the A and B arrays


Asserts the equality of the A and B arrays. The "message is displayed to the user.


Question 4. What are fixtures in JUnit?
  1.    Objects that specify when to run a test
  2.    Fixed state of a set of objects used as a baseline for running tests
  3.    Bundle of few test cases run together
  4.    Date objects
 Discuss Question
Answer: Option B. -> Fixed state of a set of objects used as a baseline for running tests


Tests need to run against the backdrop of set of predefined or known objects. This set of objects is called a test fixture.


Question 5. JUnit test files are written in files with which file extension?
  1.    .junit
  2.    .test
  3.    .java
  4.    .unit
 Discuss Question
Answer: Option C. -> .java


JUnit test files are regular java files with special methods which are referenced via annotations.


Question 6. To run the file TestClass.class from the command line, we have to type what?
  1.    java TestClass
  2.    javac TestClass
  3.    java org.junit.runner.JUnitCore TestClass
  4.    org.junit.runner.JUnitCore TestClass
 Discuss Question
Answer: Option C. -> java org.junit.runner.JUnitCore TestClass


The test cases are executed using JUnitCore class which is referenced by "org.junit.runner.JUnitCore.


Question 7. What does the fail() method do in JUnit?
  1.    Throws an assertion error unconditionally
  2.    Calls the default constructor
  3.    Outputs the message Fail" to the console
  4.    Pauses the test for 1 second
 Discuss Question
Answer: Option A. -> Throws an assertion error unconditionally


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.


Question 8. To listen to events during a test, which class has to be extended?
  1.    org.junit.runner.notification.RunListener
  2.    org.junit.runner.Listener
  3.    org.junit.runner.notification.Listener
  4.    org.junit.runner.RunListener
 Discuss Question
Answer: Option A. -> org.junit.runner.notification.RunListener


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.


Question 9. What type of object is returned on completion of a test?
  1.    org.junit.runner.Result
  2.    org.junit.runner.Complete
  3.    org.junit.runner.Outcome
  4.    org.junit.runner.Object
 Discuss Question
Answer: Option A. -> org.junit.runner.Result


An org.junit.runner.Result object collects and summarizes information from running multiple tests.


Question 10. When is the tearDown() method called in JUnit?
  1.    After all the tests have run
  2.    At the beginning of every test case
  3.    After each test case has run
  4.    At the beginning of the first test case
 Discuss Question
Answer: Option C. -> After each test case has run


The tearDown() method is called after the execution of every @Test method.


Latest Videos

Latest Test Papers