Previous Page
Next Page

7.6. Testing

Now that the Favorites view has been modified, the JUnit tests for the Favorites view need to be updated to take the modifications into account. If the tests are run as they stand, you'll get the following failure.


junit.framework.AssertionFailedError: expected.length 3,
but actual.length 0 expected:<3> but was:<0>
  at junit.framework.Assert.failNotEquals(
  at junit.framework.Assert.assertEquals(
  at junit.framework.Assert.assertEquals(
  at com.qualityeclipse.favorites.test.FavoritesViewTest
  at com.qualityeclipse.favorites.test.FavoritesViewTest
  at sun.reflect.NativeMethodAccessorImpl
        .invoke0(Native Method)
... etc ...

On closer inspection, this test is looking for the default viewer content (see Section 2.8.3, Creating a Plug-in test, on page 93). Since this default content has been removed in favor of real content (see Section 7.2.4, Content provider, on page 276), the test should be modified as follows:

public void testView() {
   TableViewer viewer = testView.getFavoritesViewer();

   Object[] expectedContent = new Object[] { };
   Object[] expectedLabels = new String[] { };

   ... code for the rest of the test ...

In a similar fashion, add code to the AddToFavoritesTest (see Section 6.3.6, Adding a test for the new action, on page 235) to assert the Favorites view content before and after the test. Since this type of assertion is duplicated in several places, it can be extracted into a new assertFavoritesViewContent method and pushed up into the AbstractFavoritesTest class.

Previous Page
Next Page