5

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.
jmj
  • 237,923
  • 42
  • 401
  • 438
Manoel
  • 71
  • 1
  • 1
  • 2
  • 1
    Does it only happen in Jenkins, or does it happen also when you start the build from the command line using Ant? Maybe this question will help you: http://stackoverflow.com/questions/1792445/running-ant-build-gives-package-org-junit-does-not-exist – Christian Semrau Jun 13 '11 at 09:15

4 Answers4

3

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

jmj
  • 237,923
  • 42
  • 401
  • 438
  • Thanks for your answer, but can you tell me how can I do it? – Manoel Jun 13 '11 at 09:16
  • download junit jar from [here](https://github.com/KentBeck/junit/downloads) , add it to your classpath. for further information check [this](http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)) – jmj Jun 13 '11 at 11:07
  • how is this configured on the jenkins server? – simgineer Mar 04 '13 at 22:00
  • @sim you should provide it in your app runtime classpath, if not under controll put it to server's lib – jmj Mar 04 '13 at 22:06
1

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 :)
Quentin
  • 1,361
  • 1
  • 9
  • 8
0

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.

Abdull
  • 26,371
  • 26
  • 130
  • 172
0

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.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347