Wednesday, 24 November 2010

eclipse, junit & static imports

It was annoying me that eclipse was not finding the static imports needed by junit 4 unit tests.

A quick google tuned up this gem, which I have grabbed below:

Open the Preferences via Window -> Preferences and select Java > Editor > Content Assist > Favorites. Add then via "New Member" the methods you need. For example this makes the assertTrue, assertFalse and assertEquals method available.

You can now use Content Assist (Ctrl+Space) to add the method and the import.

He suggests to add at least the following new members.

  • org.junit.Assert.assertTrue

  • org.junit.Assert.assertFalse

  • org.junit.Assert.assertEquals

  • org.junit.Assert.fail

I suggest also adding

  • org.junit.Assert.assertNotNull

1 comment:

Bill Comer said...

also I have just added the easyMock imports as well.

org.easymock.EasyMock.expect;
org.easymock.classextension.EasyMock.createMock;
org.easymock.classextension.EasyMock.replay;
org.easymock.classextension.EasyMock.verify;