anmastq
anmastq

Reputation: 21

Even after adding JUnit to Eclipse's build path and using import static org.junit.Assert.*, still getting cannot be resolved to error

I am trying to follow test-driven development for one of the programs. I have added the JUnit library to my build path (by Properties->Library->Add Library->Junit4) but still I am getting this error:

import static org.junit.Assert.* cannot be resolved to a type.

screenshot 1

screenshot 2

Please suggest what I can do

Upvotes: 1

Views: 3382

Answers (3)

anmastq
anmastq

Reputation: 21

I was able to solve it by performing the following steps: 1. Go to JRE System Library 2. Right Click and go to Properties. 3. Check your Environments

Upvotes: 1

nitind
nitind

Reputation: 20003

If you have a module-info.java file, it is determining what is visible to your sources from the project's Classpath/Modulepath. Add requires org.junit.jupiter.api; to its contents, also making sure JUnit 5 is on the project's Java Build Path:

module thrillioedit {
    requires org.junit.jupiter.api;
}

Or more simply, just delete the module-info.java file because JUnit 4 is not modularized.

Upvotes: 1

Borislav Stoilov
Borislav Stoilov

Reputation: 3697

You can try cleaning the whole project - project -> clean.

But you should not use IDE to manage your dependencies, like junit. Use build systems like maven or gradle.

There are plenty of good tutorials for both, and after you have that set up, just add the junit dependency in the system configuration.

Upvotes: 1

Related Questions