Skip to Content
Eclipse Cookbook
book

Eclipse Cookbook

by Steve Holzner
June 2004
Beginner to intermediate
364 pages
7h 38m
English
O'Reilly Media, Inc.
Content preview from Eclipse Cookbook

5.1. Installing JUnit

Problem

You want to install JUnit so that you can use it in Eclipse.

Solution

Add junit.jar to your project’s classpath.

Discussion

In Eclipse 2.1.x and in the current versions of Eclipse 3.0, you can find junit.jar in eclipse/plugins/org.junit_3.8.1/junit.jar.

If you’re going to be using JUnit regularly, it helps to create a new classpath variable; I named mine JUNIT. Select Window Preferences Java Classpath Variables, and click the New button to open the New Variable Entry dialog; now enter the name of the new variable—JUNIT—and the path to junit.jar.

You also can let Eclipse know where JUnit’s source code is; this is a useful step for debugging, giving Eclipse access to a JAR file’s code so that it can display it as needed. Note that this is an optional step because you don’t need to see the JUnit code. To create a new variable for the JUnit source, which we’ll call JUNIT_SRC, connect that variable to eclipse/plugins/org.eclipse.jdt.source_x.y.z/src/org.junit_3.8.1/junitsrc.zip, where x.y.z is your version of Eclipse. Then right-click your project, click Properties, click the Java Build Path node and the Libraries tab, and then expand the node for the JUNIT entry, as shown in Figure 5-1.

Making source code accessible to Eclipse

Figure 5-1. Making source code accessible to Eclipse

When you expand a JAR file’s node, you can specify where to find the associated source code and Javadoc. To use JUNIT_SRC

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Eclipse

Eclipse

Steve Holzner
Official Eclipse 3.0 FAQs

Official Eclipse 3.0 FAQs

John Arthorne, Chris Laffra

Publisher Resources

ISBN: 0596007108Catalog PageErrata