Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - package org.junit does not exist even though dependency added

Tags:

java

junit

maven

I'm creating testing class to my maven project, but maven can't import JUnit, any ideas why?

class Recipebook/src/test/java/RecipebookTest.java:

 import org.junit.Test;
 import org.junit.Before;

 /**
  *
  * @author Mimo
  */
 public class RecipebookTest {
     @Before
     protected void setUp() throws Exception {        
     }
 }

my pom.xml file:

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>

   <groupId>fi.muni</groupId>
   <artifactId>Recipebook</artifactId>
   <version>2.1.0</version>
   <packaging>jar</packaging>

   <name>Recipebook</name>
   <url>http://maven.apache.org</url>

   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>

   <dependencies>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
     </dependency>
   </dependencies>
 </project>

thanks

like image 269
Miloš Lukačka Avatar asked Mar 10 '13 16:03

Miloš Lukačka


People also ask

How do I fix Java package org junit does not exist?

The solution to this is to add junit library as dependency to the project. This can be done by adding junit to global library and then hovering over the error(junit word) and right clicking to add junit to class path.

What is junit package?

It is an open-source testing framework for java programmers. The java programmer can create test cases and test his/her own code. It is one of the unit testing framework. Current version is junit 4.


1 Answers

Wrong junit, you need version 4 for annotations. Change the dependency to:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
</dependency>
like image 69
Boris the Spider Avatar answered Sep 30 '22 20:09

Boris the Spider