CS494, Spring 05


In-lab exercise, Jan 28:

  1. This doc explains how to install Eclipse and Java at home.
    Also, it has a short "getting started" exercise -- do this in lab!
  2. Listen to someone tell you about Eclipse using these slides.
  3. Work through JUnit example in photocopy-handout I've given you from the Eclipse Kick Start book. Here you'll create a new project for the Greeter example.
  4. Using the article Test Infected - Programmers Love Writing Tests, do the following.
    But... don't just copy or paste in the code snippets you see in the article. The steps below as you to do these in a way that shows how Eclipse makes it easier. The point here is to see how Eclipse helps, so please do things as described. And, it only makes sense if you've read the handout from the Eclipse Kick Start book.
    1. Use Eclipse to create new project (call it, say, infected, with a class Money in the package edu.virginia.cs494, and add constructor code first (without typing in fields). Use Quick Fix to create fields.
    2. In the Outline view, select one of the fields, right-click and choose Source and then Generate Getters and Setters. Explore this to create to getters for these two fields (but not setters). If you want, you can rename them to match the Test Infected article.
    3. Look at the Source menu at the top of the Workspace. What can you do with this? (Well, you could have done the last step from here.) See what else is interesting to you. (Sort Members is kind of cool, if you like to be organized.)
    4. Create a TestCase class for Money by selecting the class (where? anywhere?) and right-clicking and making a new JUnit Test Case. Go ahead and add setUp() and tearDown() method for now.
    5. It's time to get an add() method, but write the test first!
      In MoneyTest start typing the code from the Test Infected article for testSimpleAdd() but call it testAdd(instead). Note the error when you type in the add() method, but just use Quick Fix to let Eclipse generate the method for you.
    6. Carry on (in lab or later) with the Test Infected example. Each time, create the test first in the MoneyTest class and let generate the skeleton for the method.