Continuous Testing Tutorial for PS0

This material is taken from the on-line help for the Continuous Testing plug-in version 2.0.

Contents:

What is Continuous Testing?

Simply put, Continuous Testing helps you get a better grade in 6.170, if you're already using Eclipse. In a controlled experiment in Fall 2003, students who used continuous testing were 50% more likely to turn in completely correct problem sets than those who only used continuous compilation (the standard Eclipse functionality), while spending no more time on their problem sets.

This tutorial assumes that you have completed Problem Set 0 using Eclipse. (If you've successfully completed the assignment, you may want to turn it in before continuing.) It also assumes that you have already installed continuous testing. If you are on an Athena machine, using the provided runeclipse script, continuous testing has already been installed for you. If you are on a personal workstation, please follow the on-line instructions to install the continuous testing feature into Eclipse. You will need to have installed Eclipse version 3.2M4. If you upgrade from a previous version, you will need to reconfigure your default workspace, but all other settings should carry over.

With continuous testing enabled, as you edit your code, Eclipse runs your tests quietly in the background, and notifies you if any of them fail or cause errors. Continuous testing builds on features of Eclipse with which you are already familiar, such as compile error notification: As soon as you write code that contains a compilation error, Eclipse highlights the error in the text and the margin, and creates a task in the Problems table. With continuous testing, you get the same kind of notification when you write or edit code that causes one of your tests to fail.

The developers of continuous testing are very interested in your feedback. Please contact us with any and all comments or complaints. You can also ask a staff member, such as an LA, for help

Enabling Continuous Testing

Since continuous testing is already installed, it's time to enable it for our project. First, we need to make sure that continuous testing's feedback will not be filtered out. In the Problems view, click the "filters" button on the upper right: it has three arrows pointing to the right. A dialog box will appear. Look for the checkboxes labelled "Show items of type:". Make sure that Test Failure is checked.

Now, we will enable continuous testing on the psets project:

  1. Right-click the psets project in the Navigator view, and select "Properties".
  2. Now, in the selection list on the left, choose "Continuous Testing Properties".
  3. Select "Enable Informed Testing" and "Enable Continuous Testing".
  4. Click the "Edit" button in the Launch Configuration box.
  5. A dialog will pop up, and you should single click Continuous Testing Launch in the configuration box and click the New button. A launch will be created with a Default test loader.
  6. Select the radio button for "run all tests in the selected project, package, or source folder", and make sure the selected project is the "test" subfolder of the pset you want to test. Leave all the rest of the default values unchanged.
  7. Hit OK, and then when you are back to the Properties window, press "OK" once more.
You will need to complete these steps for all future projects for which you want Continuous Testing, after checking out the staff provided code from CVS, but before you start each problem set.

All of your tests will run in the background immediately after you enable continuous testing. If you had closed or hidden the JUnit view in the past, it may have been brought to the front. If you wish, you can prevent this behavior by clicking a white downward arrow in the upper right of the JUnit view, and selecting "Active on Error/Failure only". You may notice multiple failure markers in the Problems View, if you still have failing tests.

Error Notification

Let us take a look at a Test Failure. If you've already successfully completed problem set 0, you should now introduce a bug into your code. For example, change HolaWorld.getGreeting to read:

public String getGreeting() {
  return "No hablo Espanol";
}

In the Problems View, you will notice a Test Failure marker for testGreeting(ps0.HolaWorldTest). The method testGreeting() is currently as follows:

  public void testGreeting() {
	HolaWorld world = new HolaWorld();
        assertEquals(HolaWorld.spanishGreeting, world.getGreeting());
    }
    

We expect this test to fail since the two strings being compared are not equal. You'll see several indications of the failing test, similar to what you see when there is a compile error in your code:

Although the same kind of notifications are used for compile errors and test failures, the two kinds of problems are different. Most importantly, compile errors are usually indicated near the code that needs to be changed, whereas test failures are indicated on the test method that failed. To fix a test failure will often require making a change in the code being tested, somewhere far away from the failure notification.

What You Don't See

Before we go farther, it's worth quickly pointing out a few things that you might expect to see, but don't. Continuous testing tries hard not to bother you unless there's something you really need to know.

First, notice that the tests being run by continuous testing do not appear in the the JUnit result view. This place is reserved for launches that you initiate manually. If you would like to see the results of a test run by continuous testing, select the menu "Run > Run History", and select the name of your continuous testing launch configuration from the list. Or, if there is a test failure marker in the Problems view, you can right-click it, and select "Rerun" (see "Rerun Tests" below.)

There are other subtle ways that continuous testing tries to stay out of your way. First, if there is a compile error anywhere in the project you are editing or the project containing the tests, or in those projects' dependencies, no tests are run. Second, even if two projects are associated with the same test, only one failure marker per test is ever created.

Context Menu Options

Right click on the test failure that has currently been created in the Problems View. You'll see some standard options, including "Go To", "Copy", and "Properties", as well as four options specific to continuous testing:

Fixing Tests

Fixing the test failure in our case can be as simple as changing the method getGreeting() to be
public String getGreeting() {
  return "Hola Mundo!";
}
This may not be the correct solution to the problem in PS0, but it is a quick way to see how test failure markers are added and removed from the Problems View. Upon saving this change, the tests will rerun, and the Test Failure marker for testGreeting(ps0.HolaWorldTest) will be removed from the Problems View.

Contact us!

Congratulations on completing the tutorial. Again, the developers of continuous testing are very interested in your feedback and questions. Please contact us with any and all comments or complaints. Also feel free to use the LAs and other course staff.

Troubleshooting (in case of problems in continuous testing)

If you get an error message like "plug-in edu.mit.lcs.pag.continuoustester was unable to load class edu.mit.lcs.pag.continuoustester.project.ContinuousPropertyPage", that indicates that Eclipse was unable to load a plug-in's classes. To get a detailed error message that's more likely to pinpoint the root cause of these problems, users should look in the error log (.metadata/.log in the file system, or the Error Log view in the UI) for a stack trace near the time of startup complaining about the continuoustester plug-in.

When there is a classloading problem, the two most common problems are:

  1. The user is using an incompatible version of Eclipse or the JRE.
  2. The user has recently installed a compatible version of Eclipse on top of an incompatible version, in which case a single invocation of "eclipse -clean" from the command line can be useful.