eskoba
eskoba

Reputation: 566

why is junit not not visible at all in my eclipse java compiler

I am relatively new in java programming specifically with eclipse environment. I am trying to use junit and tried the following

import org.junit.*; 

however this is not working because junit is not part of the org package. nevertheless junit is installed on my computer. please could anyone tell me what could be wrong. from the java tutorials I have read so far, nothing is wrong with my code

Upvotes: 2

Views: 1451

Answers (3)

Reimeus
Reimeus

Reputation: 159844

The JUnit JAR file is not included in the project build path.

Include the JAR file in project classpath for the current Eclipse project. Ensure the file is visible from the Package Explorer View. Then right click on the JAR file and select

Build Path > Add to Build Path

Alternatively, if you're using Maven, you can simply add the JUnit dependency your project's POM.XML file

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
</dependency>

Upvotes: 2

A4L
A4L

Reputation: 17595

You need to add the junit library to the classpath of your project.

In Eclipse you can do it like this:

right click on your project then go to

Build path > Configure Build path...

switch to the Libraries tab then click add Library. Choose JUnit and hit next, choose witch version you want, 3 or 4 (I recommend 4). Hit finish then hit OK.

That's it.

Upvotes: 2

Bruce Martin
Bruce Martin

Reputation: 10543

Following onfrom reimus, For my version of eclipse (other version may differ):

  • Try right clicking on the package
  • Select build path
  • Select add libraries
  • Select JUnit
  • etc

You should then be able to use JUnit

Upvotes: 1

Related Questions