Sun Java Solaris Communities My SDN Account Join SDN
 
Quizzes

JUnit in Action Quiz

 

Quizzes Index

By Vincent Massol
April 2004

Duke

Test your JUnit knowledge with this quiz which is based on all chapters of the book, JUnit in Action; the majority of questions are focused on chapter 7. If you don't know the answer, take your best guess.

 

  1. When talking about "test" and "test case", which assertion is true?
     A. A "test case" represents a test that is being executed.
     B. A "test" is synonymous with "test case".
     C. A "test case" holds several "tests".

  2. What is a JUnit test fixture?
     A. The set of operations performed to set the test environment in a known state before a test starts
     B. A set of tests regrouped together so that they can all be easily run by a JUnit TestRunner
     C. The name for the set of tests that comprise a TestCase

  3. Among these test name examples, what is the name you would choose for naming a test exercising an exception flow?
     A. testProcessRequestException()
     B. testProcessRequestWhenNoMatchingHandlerFound()
     C. handleNoMatchingHandlerWhenCallingProcessRequest()

  4. When is the JUnit setup() method called?
     A. Before each TestSuite
     B. Before each TestCase
     C. Before each test

  5. What would you use in a test to verify that an object is not null?
     A. assertNotNull("The response cannot be null", response);
     B. assertNotNull(response);
     C. if (response == null) { throw newException("The response cannot be null"); }

  6. When testing an error flow, what test would you write?:
     A.
    public void testErrorCase() throws Exception
    {
        methodToTest();
        // Asserts here
    }
     B.
    public void testErrorCase()
    {
        try
        {
            methodToTest();
        }
        catch (Exception expected)
        {
            // Asserts here
        }
    }
     C.
    public void testErrorCase()
    {
        try
        {
            methodToTest();
            fail("Should not reach this point");
        }
        catch (Exception expected)
        {
            // Asserts here
        }
    }

  7. The mock objects strategy is
     A. a strategy to purely unit test code
     B. a strategy to improve code design and to unit test code
     C. a strategy to develop code faster

  8. What is the Inversion Of Control pattern?
     A. Classes use factory classes whenever they require a domain object.
     B. Caller classes control child classes they call and pass to them domain object they require.
     C. Child classes return domain objects to parents.

  9. What is a mock object?
     A. A test object that replaces a real object, synonymous to stub
     B. A probe that you insert in your code under test and whose behavior is completely controlled by the tests
     C. A runtime replacement for a real object that you can turn on during testing and off when the application runs in production

  10. When doing refactoring to allow introduction of mock objects, what is the disadvantage of the Method Factory refactoring technique (i.e. add a new method and create a class that extends the class to test and that overrides the new method to swap-in the mocks)?
     A. It is complex as it requires both creation of a new method and overriding the class to test.
     B. It is not completely reliable as you are now not testing the real class.
     C. It is a bad practice as you're changing the code under test in the process.

  11. In addition to simulating the API of the class it replaces, what is a mock object also capable of?
     A. Providing verification about method calls (parameters passed, etc)
     B. Making the coffee
     C. Generating test coverage reports about what methods have been called during tests and what have not

  12. From the list below, which framework is not a mock object framework?
     A. MockObjects.com
     B. jMock
     C. JavaMock
     D. EasyMock