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.

testView(com.qualityeclipse.favorites.test.FavoritesViewTest)

junit.framework.AssertionFailedError: expected.length 3,
but actual.length 0 expected:<3> but was:<0>
  at junit.framework.Assert.fail(Assert.java:47)
  at junit.framework.Assert.failNotEquals(Assert.java:282)
  at junit.framework.Assert.assertEquals(Assert.java:64)
  at junit.framework.Assert.assertEquals(Assert.java:201)
  at com.qualityeclipse.favorites.test.FavoritesViewTest
        .assertEquals(FavoritesViewTest.java:125)
  at com.qualityeclipse.favorites.test.FavoritesViewTest
        .testView(FavoritesViewTest.java:93)
  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