Eclipse and JUnit Exercise

  1. Download the jar file containing the source for JUnit from here.
  2. Start Eclipse, and create a new project called junit. It's fine for this to be a either a Java 1.4.2 or Java 1.5 project.
  3. Right-click on the src folder in the package perspective, and choose Import. Here are the steps to import files from the jar file for this project.
    1. Choose the source, usually either a file system or a Zip file (which also includes jar files)
    2. Hit Next and in the next screen use Browse to find your jar file.
    3. You might play with expanding the directory tree view you see here. You check boxes to indicated which folders/files you want to import.
    4. For this lab, un-check the top-level folder, but then check the junit sub-folder. And then...
    5. Click FilterAll and see what that does. If you just want Java files, you should click that option. If you want all files except class files, click SelectAll and then de-select the class extension. For this lab, we can take everything. Or just the java files. Either way.
    6. Click Finish, and watch the progress, including down in the bottom-right.
    7. Back in the Package perspective, expand the src directory to see your project files.

  4. Open the framework package and answer the following questions.

Question 1: Where are the assertion functions used in JUnit defined? We call them as if there were globally defined functions like we have in C++, but Java doesn't allow that (does it?).

Question 2: What Java mechanism/technique/hack is used to accompish this?

Question 3: In what sense of inheritance is TestCase a subclass of its supertype? Explain if this seems a good OO design. If not, explain why the JUnit authors might have done this.

Question 4: Choose TestSuite and invoke the type hierarchy perspective. What are its superclass(es) and subclass(es)?

Question 5: Use the type hierarchy to show what interfaces TestSuite implements.
Then, go that interface, invoke the type hierarchy viewer again on that, and write down what classes implement that interface.

Question 6: Examine Test, TestSuite, and TestCase. Explain or draw why this is an example of the Composite design pattern.

Question 7: How does this example differ from the drawing and description of Composite given in the handout? Do you think this is OK in terms of it still being a Composite? Why did the authors of JUnit do it this way?

Question 8: In the handout, the pattern description shows that the AbstractComponent class has methods (or signatures) for all of the methods in its subtypes. Is that true here? Why not? Can you think of design reasons deciding whether or not to put them all in the superclass?