views:

597

answers:

3

I've got Hudson running on TOMCAT, it can build my Netbeans project using the ant build.xml, but it won't run any of my unit tests because of what I assume is a problem with the classpath:

package org.junit does not exist
    [javac] import org.junit.After;
    [javac]                 ^

But I've got the junit-4.8.1.jar on the classpath in /etc/environment and I can successfuly run the junit tests from a console using

java org.junit.runner.JUnitCore org.junit.tests.AllTests

My CLASSPATH is set to /home/bedwyr/junit4.8.1/junit-4.8.1.jar:.

Am I going wrong somewhere or is there anything else I need to set?

[edit]

What I did was to export/include (using the ide) all libraries (including Junit) hudson then reads all it needs from the subversion repo.

I then ran into an issue with exposing hudson to the internet, and pretty soon gave up on tomcat on ubuntu server (again, to do with the tomcat security manager) - glassfish is a lot smoother and that's where I am now - apache front end with ajp_proxy to hudson on glassfish.

+1  A: 

You need to properly set your classpath whether you're using Ant or Maven to perform your build.

Using Ivy with Ant or switching your build to Maven will allow the build to automatically lookup dependencies and properly set the classpath. If neither of those is an option you need to do something similar to the following in Ant.

<property file="build.properties" />
<property name="junit-home" location="/etc/environment" />

<path id="test.compile.classpath">
  <path refid="compile.classpath" />
  <pathelement location="${junit-home}/junit-4.8.1.jar" />
  <pathelement location="${target}" />
</path>

The build.properties part will allow you to override the default junit-home if it is different for individuals and hudson.

Another way to modify properties is when invoking Ant from Hudson there is an advanced section which allows you to pass a properties file or a properties form which would allow you to enter key value pairs in the following format:

junit-home=/etc/environment
Rob Spieldenner
A: 

The junit jar is on the classpath but it is not packed somewhere in the netbeans project folder.

Solution: remove the auto-added junit lib from your netbeans project (test library) and then explicitely add the junit jar via right clicking 'test libraries' -> 'add jar/folder'

Karussell
A: 

You can export environment variables in Hudson. There is a plugin for it.

http://wiki.hudson-ci.org/display/HUDSON/Setenv+Plugin

But solution suggested by Rob makes more sense. Here, you don't have to worry where you run. Depending on environment variable is not a very good idea. Since it affects all programs you run.

Jigar Shah