Classpath issue with JUnit tests

I switched to JUnit 3.8 style tests (extending TestCase instead of using annotations) due to the JUnit4 problems described in the "Agra and JUnit4" thread.

Now the tests are run (using Ipr runner), but there seems to be a problem with the classpath:
Every test, that tests a class where somtheing like "getClass().getRessource()" is used, fails.
E.g., one class under test (Version) includes the following code:

private static final String VERSION_FILE_NAME = "/de/czms/hydra/system/version/version.properties";

public Version() throws IOException {
Properties prop = new Properties();
InputStream is = getClass().getResourceAsStream(VERSION_FILE_NAME);
prop.load(is);
}

A unit test calling Version version = new Version(); runs perfectly well under IDEA, but when run in TeamCity with the Ipr runner, a NullPointerException occurs, because the InputStream "is" is null.

The same thing happens in a class named "Utilities" for a line like
protected final static ImageIcon ERROR_OV = new ImageIcon(Utilities.class.getResource("/res/error_ov.png"));
The ImageIcon constructer throws a NPE when a test case using class "Utilities" is run by TeamCity Ipr runner, while it works when run in IDEA.

6 comments
Comment actions Permalink

I just noticed that the same problem exists in TeamCity 1.2

Everything that uses class.getResource (or similar) will fail when run by TeamCity Ipr runner. :(

0
Comment actions Permalink

Hi Tobias,

Could you please run file search for version.properties file in buildAgent/work/(Server|Agent|Manual)/projectName directory (this is the place which should contain your project sources on a build agent).
This search should reveal whether resource files are copied to output path.
Please file results, your project and integrationBuild.* files from the directory as separate Jira issue.

Thanks!
KIR

0
Comment actions Permalink

Tobias,

I suppose you have invalid ipr file.
Your IPR file should contain section like the following:

]]>

Please check this.

Kind regards,
KIR

0
Comment actions Permalink

Well, I wouldn't say my Ipr file is invalid, the section looks a little but different though:

]]>

The expression "!?.java" works fine in IDEA (copies everything that doesn't end with .java to the output path, but it doesn't work in TeamCity (neither 1.2 nor Agra):
Here, no resources are copied at all.

I tried it with your entries, and it works then.

The behavior should be the same here for IDEA and TeamCity.

0
Comment actions Permalink

Hi Tobias,

I see your point, though I never knew such syntax work in IDEA.
Please watch http://www.jetbrains.net/jira/browse/TW-2167 and please try using inclusion pattern as a workaround.

Kind regards,
KIR

0
Comment actions Permalink

Actually, the expression "!?.java" is very usefull:
You don't have to maintain the setting every time you deal with a new kind of resource. E.g. ".xsd" isn't included in the default list, and if you do something with fonts, you have to add ".TTF" manually and so on.

But thanks a lot for your hint, it would have token me forever to figure that one out as one of the basic steps when I set up a new project is, is to change the pattern to "!?.java"...

0

Please sign in to leave a comment.