3
votes

I am using Intellij Idea version 12 (ultimate). Just installed Team City (version 8). One default agent, running in linux.

I've created a very simple test application:

public class Main {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }

    public int sum(int x, int y) {
        return x+y;

    }
}

... and a very simple test...

import junit.framework.Assert;
import org.junit.Test;

public class MainTest {
    @Test
    public void testSum() throws Exception {
        Main test=new Main();
        Assert.assertEquals("Sum should be 7",7,test.sum(4,4));
    }
}

If I run this in IntelliJ, the test gets run and fails just like it should.

If instead I commit this project and push it up to github, TeamCity sees the change and begins a build. The build fails fairly quickly with the following errors:

/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:1: package junit.framework does not exist 
import junit.framework.Assert; 
                      ^ 
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:2: package org.junit does not exist 
import org.junit.Test; 
                ^ 
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:12: cannot find symbol 
symbol  : class Test 
location: class MainTest 
    @Test 
         ^ 
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:15: cannot find symbol 
symbol  : variable Assert 
location: class MainTest 
        Assert.assertEquals("Sum should be 7. Loser!!",7,test.sum(4,4)); 
                ^

So yeah, I see that TeamCity is not seeing JUnit.

On the TeamCity Discussion forum, one respondent to my question there asked me if junit.jar was added as a dependency (module or library) in the build. It was listed as a module dependency, but for kicks I tried it as a library dependency. I also tried checking and unchecking export and trying the compile and test scopes, but each time I get the same errors. My run configuration is shared.

I am not using Ant or Maven. Perhaps someday, but I'd like to start as simple as possible.

Clearly, I'm missing something, but the documentation on the subject is sparse.

Thank you.

1

1 Answers

3
votes

So I heard back from Jetbrains tech support this and, in the interest of completeness and saving someone else the trouble, here's the response I received:

Seems the problem is that junit.jar is not placed in version control under your project. In order to build your project on TeamCity agent, the project ideally should be self contained. In your case junit.jar only exists on your local machine, I suppose there is no such file on agent at required location. So you have two options actually: put junit.jar under version control into your project, or define global library in IDEA and configure this global library on IDEA Project runner page (Check/Reparse must be started), after that put library files on all of the agents where your build will be executed. Personally, I think the first approach is much simpler and better.

I added junit to version control and now the build works properly in TeamCity.