Running jenkins gives “package org.junit does not exist”

∥☆過路亽.° 提交于 2019-12-19 08:16:29

问题


Can any one please help me with that error?

build-project:
     [echo] AntProject: /root/.jenkins/jobs/Ant/workspace/build.xml
    [javac] Compiling 2 source files to /root/.jenkins/jobs/Ant/workspace/bin
    [javac] /root/.jenkins/jobs/Ant/workspace/src/com/moi/test/junit/MaClasseTest.java:3: package org.junit does not exist
    [javac] import static org.junit.Assert.*;
    [javac]                        ^
    [javac] /root/.jenkins/jobs/Ant/workspace/src/com/moi/test/junit/MaClasseTest.java:5: package org.junit does not exist
    [javac] import org.junit.Test;
    [javac]                 ^
    [javac] /root/.jenkins/jobs/Ant/workspace/src/com/moi/test/junit/MaClasseTest.java:9: cannot find symbol
    [javac] symbol  : class Test
    [javac] location: class com.moi.test.junit.MaClasseTest
    [javac]     @Test
    [javac]      ^
    [javac] /root/.jenkins/jobs/Ant/workspace/src/com/moi/test/junit/MaClasseTest.java:12: cannot find symbol
    [javac] symbol  : method assertTrue(boolean)
    [javac] location: class com.moi.test.junit.MaClasseTest
    [javac]              assertTrue(MaClasse.additioner(2,2) == 4); 
    [javac]              ^
    [javac] 4 errors

BUILD FAILED /root/.jenkins/jobs/Ant/workspace/build.xml:35: Compile failed; see the compiler error output for details.

回答1:


it seems you forgot to make junit library available in your classparh




回答2:


My solution :

  • Download junit.jar
  • In the projet.properties file, find the line "javac.test.classpath=\" and add at the end /your/path/to/junit-4.10.jar
  • you can test locally to see if it works
  • push on github
  • build on jenkins and voila it works :)



回答3:


You need to provide a compilation classpath to javac, which includes junit.jar.

Check the <classpath> tag inside <javac> for one way to solve this.




回答4:


I ran into this problem because I accidentally put the failing JUnit test Java source file to location src/main/java/... instead of the correct src/test/java/....

My IDE Eclipse didn't complain about missing imports and would happily run tests from that file while it was located at src/main/java/... — while Jenkins would abort building, and therefore testing.

Moving the problematic file to the correct location, src/test/java/..., resolved my issue.



来源:https://stackoverflow.com/questions/6328529/running-jenkins-gives-package-org-junit-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!