The import org.junit cannot be resolved

前端 未结 13 2048
梦谈多话
梦谈多话 2020-12-04 09:49

I need to solve a java problem for an interview, and they have sent me the test class. It starts with

import org.junit.Before;

and also ha

相关标签:
13条回答
  • 2020-12-04 10:23

    you can easily search for a line like "@Test" and then use the quickfix "add junit 4 library to the build path" at this line. i think this is faster than adding junit manually to the project.

    0 讨论(0)
  • 2020-12-04 10:28

    Update to latest JUnit version in pom.xml. It works for me.

    0 讨论(0)
  • 2020-12-04 10:29

    If you are using eclipse and working on a maven project, then also the above steps work.

    Right-click on your root folder.

    Properties -> Java Build Path -> Libraries -> Add Library -> JUnit -> Junit 3/4
    

    Step By Step Instructions here

    0 讨论(0)
  • 2020-12-04 10:31

    You need to add junit library to the classpath of your project. There are several choices to achieve it depending on your development setup.

    1. Command line: In the case of command line invocations, you will have to add junit.jar to the classpath of your application with java -cp /path/to/junit.jar. Take a look at the answers here.

    2. Using eclipse: Eclipse distributions are bundled with this library and this is how you can use it for your project. Right click on the eclipse project and navigate:

    Properties -> Java Build Path -> Libraries -> Add Library -> JUnit -> Junit 3/4

    In the scenarios where you want to use a different version of the jar, instead of clicking on Add Library above you should click on Add External Jar and locate the library on the file system.

    0 讨论(0)
  • 2020-12-04 10:33

    In case you want to create your own Test Class. In Eclipse go to File -> New -> J Unit Test Case. You can then choose all your paths and testing class setup within the wizard pop-up.

    0 讨论(0)
  • 2020-12-04 10:36

    Right-click on the eclipse project and navigate:

    Properties -> Java Build Path -> Libraries -> Add Library -> JUnit -> Junit 3/4

    It works on mine.

    0 讨论(0)
提交回复
热议问题