Basic Eclipse Setup for TDD
Today I like to share my basic setup for TDD with Eclipse.
- Get Eclipse:
I'm sure you know where you get Eclipse but just for the complete picture you can download it here: http://www.eclipse.org/downloads/. I prefer the "Eclipse IDE for Java EE Developers". - Install and start Eclipse:
- After you downloaded the compressed IDE, just extract it in your preferred program folder and lunch the executable.
- Select your workspace folder:

- After you have closed the "welcome" tab you are ready to start.

- Install the continuous test runner:
I use infinitest as a continuous test runner. It is a plug-in for eclipse which continuously runs the JUnit tests that are relevant to the files I just changed. So I get immediate feedback and have not to interrupt my flow for test execution.
There are install instructions on the infinitest page so not go to repeat them here.
After the installation you see the infinitest bar in the lower right corner of eclipse:

- Create the project:
- Now it is time to create your project. Just click on "File -> New -> Project..." and select "Java Project" in the "New Project" wizard. Click on "Next".
- Enter a "Project name" in the wizard and click "Finish"

- Add libraries:
- Create a new Folder in your Project ("New -> Folder") called "libs".
- I use easyMock as mocking framework.
- The latest version can be downloaded on the easyMock download page.
- The downloaded archive file contains the lib and documentation, etc. You only need the easymock-x.x.jar file. Copy it to your
just created "libs" folder.
(On you filesystem you find it in [Your Project] folder located in the workspace folder you selected at eclipse start.)
- Hamcrest provides a lot of usefull matcher objects for JUnits assertThat (you
know assertThat, right?) and mock expectations.
- Download the latest (stable) hamcrest-all-x.x.jar from the download list and store the file in your "libs" folder.
- Now you should have the following structure in your "Project Explorer":

- Add the libraries to your buildpath:
- Right click on [Your Project] -> "Build Path" -> "Configure Build Path..." and than select the "Libraries"
tab.

- Click on "Add JARs..." and select the two jar files in your "libs" folder.

- Close the "JAR Selection" with a click on "OK".
- Click on "Add Library..." choose "JUnit" and click on "Next". Then select "JUnit 4" and close the dialog with "Finish".
- Close the "Java Build Path" Config Dialog with click on "OK".
- Right click on [Your Project] -> "Build Path" -> "Configure Build Path..." and than select the "Libraries"
tab.
- Add favorites for static types:
With favorites for static members or types the content Assist will propose the favorite members or members of the favorite types and add the static import automatically.
You find the configuration on: "Window -> Preferences -> Java -> Editor -> Content Assist -> Favorites".
I use to add the types: "org.junit.Assert.*", "org.hamcrest.Matchers.*" and "org.easymock.EasyMock.*".
Thats it. You can start to write your first JUnit TestCase.
Ok in general I use Maven for the dependencies and also add a version control system.
Tags:
Published at DZone with permission of its author, Christoph Pater.(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)





Comments
David Grant replied on Fri, 2011/04/08 - 2:31am
Christoph Pater replied on Fri, 2011/04/08 - 3:40am
in response to: davidjgrant
Puneet Monga replied on Fri, 2011/04/08 - 2:08pm
Christoph Pater replied on Sat, 2011/04/09 - 1:36pm
in response to: mongapuneet
James Ervin replied on Tue, 2011/04/26 - 6:19pm
Liezel Jane Jandayan replied on Mon, 2011/08/22 - 9:02pm
Eclipse is a Java program, but it uses a custom user interface toolkit that does not run on all platforms that supports Java 2. Check the web site for supported platforms. Eclipse requires a Java 2 runtime, so you need to install the Java 2 SDK first before installing Eclipse.Yochanan Berkowitz
Niko Miko replied on Tue, 2011/09/20 - 6:12am
Christoph Pater replied on Thu, 2011/12/01 - 3:39pm
in response to: cpater