Over a million developers have joined DZone.

Basic Eclipse Setup for TDD

DZone's Guide to

Basic Eclipse Setup for TDD

· Java Zone ·
Free Resource

Java-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.

Today I like to share my basic setup for TDD with Eclipse.

  1. 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".
  2. 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.
  3. 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:
  4. 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"
  5. Add libraries:
    1. Create a new Folder in your Project ("New -> Folder") called "libs".
    2. 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.)
    3. 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.
    4. Now you should have the following structure in your "Project Explorer":
    5. 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".
  6. 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.

Connect any Java based application to your SaaS data.  Over 100+ Java-based data source connectors.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}