Jenkins can't find JUnit (Netbeans + Git + Ant + JUnit + Jenkins)

How to get Jenkins to find JUnit when creating with Ant?

Reading the answers here and here I believe that I have a problem with the classpath, but I cannot solve it. In my Netbeans project, I have one JUnit test that works fine in Netbeans. I push the project to my Git repository and Jenkins sees the change and builds the project, but I get a bunch of errors (below) because JUnit was not found.

-do-compile-test: [javac] Compiling 1 source file to C:\Jenkins\jobs\demo\workspace\demo\build\test\classes [javac] C:\Jenkins\jobs\demo\workspace\demo\test\MainTest.java:6: package org.junit does not exist [javac] import org.junit.After; [javac] ^ [javac] C:\Jenkins\jobs\demo\workspace\demo\test\MainTest.java:7: package org.junit does not exist [javac] import org.junit.AfterClass; [javac] ^ 

JUnit is located in my %ANT_HOME%\lib directory (Windows 7 64 bit). The file structure of my Netbeans project is as follows:

enter image description here

I tried to edit the class path through Ant, as described here, but I cannot get it to work correctly.

This is my first exit with Ant, JUnit, and Jenkins, but I think I'm really close to getting everything working correctly with Netbeans and Git. I gladly provided more information. Fighting this for 3 days, so any help would be greatly appreciated.

+4
source share
3 answers

I know that it’s too late to answer, but now we have a solution to this problem ...

I have the same problem. I have a project created using ant, I decided to include in the build.xml paths to junit.jar and hamcrest-core.jar

  • Download junit.jar and hamcrest-core.jar from the junit repository in git: https://github.com/junit-team/junit/wiki/Download-and-Install

  • paste files somewhere in jenkins / hudson server

  • edit your build.xml file adds the following lines:

     <property name="JUNIT_HOME" value="path_to_folder_contain_junit_&_hamcrest_jars"/> <path id="JUnit 4.libraryclasspath"> <pathelement location="${JUNIT_HOME}/junit.jar"/> <pathelement location="${JUNIT_HOME}/hamcrest-core.jar"/> </path> <path id="projectname.classpath"> <pathelement location="your_bin_folder"/> <path refid="JUnit 4.libraryclasspath"/> </path> <!--in your javac task include the classpath --> <javac debug="true" debuglevel="${debuglevel}" destdir="your_bin_folder" source="${source}" target="${target}"> <src path="src"/> <classpath refid="projectname.classpath"/> </javac> 
  • Transfer the file to your svn, git, to any server.

  • Try to build. junit is now in your class and jenkins can complete the build

+1
source

try to provide the full path fie relative to the current directory, so the ur test results are examined in nbproject , and the current working directory is demo

In the Publish JUnit Results section, write

 nbproject/*.xml 
0
source

You can handle this in NetBeans without downloading Ant files yourself.

You must

  • Download the Junit and Hamcrest JAR files and save them in the lib / directory of your application.
  • In NetBeans, right-click your project, select Properties, and then Libraries on the left. Go to the "Compilation fees" tab, delete the Junit libs system nodes and add them from your lib / directory using the "Add JAR / Folder" button.

Make sure you add the appropriate Ant files ([project] /build.xml and [project] /nbproject/build-impl.xml to your VCS.

Then just tell Jenkins where the Ant file is located (the path to [project] /build.xml in your repo) and which Ant is meant to run (usually this is a "test jar" for a Java SE application).

This solution also has the advantage that it works if you cannot (or do not want) to store individual files on the CI server manually. The disadvantage is that you send files with your application instead of using system-wide libraries that may already be available on the server.

0
source

Source: https://habr.com/ru/post/1387614/


All Articles