views:

163

answers:

3

Hello,

I recently upgraded from NetBeans 6.7.1 to NetBeans 6.9 and my old JUnit tests are showing "cannot find symbol" errors in the NetBeans editor around the import statements.

Everything builds correctly on these unit tests and I can still run/debug the unit tests without any issues. However, auto-complete within the editor doesn't work at all for the classes it can't find. This is making it difficult to create new JUnit tests.

I can import classes from another module within the suite correctly. Java API classes also import without issue. This seems like a dependency issue, but I don't know how to fix it.

Here's the hypothetical NetBeans project structure I'm running on:

MyCodeSuite
- MyNetBeansModule1
- - Source Packages
- - - com.company.module1.foo
- - - - DoSomething1
- - - - DoSomethingElse1
- - - - ClassInQuestion
- - Unit Test Packages
- - - com.company.module1.foo
- - - - ClassInQuestionTest
- MyNetBeansModule2
- - Source Packages
- - - com.company.module2.foo
- - - - DoSomething2
- - - - DoSomethingElse2

ClassInQuestionTest.java:

package com.company.module1.foo;

import com.company.module1.foo.DoSomething1;  // this is where the editor starts showing errors; these errors are propagated throughout the code anywhere "DoSomething1" shows up
import com.company.module2.foo.DoSomething2;  // the editor doesn't complain for this one

// These imports all work correctly
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

I've duplicated this for new unit tests as well as existing unit tests. It doesn't matter what class I'm importing from thecom.company.module1.foopackage. The editor shows errors for any class within that package and within that same module.

Also, note that I'm using the "Create JUnit Tests" context menu item within NetBeans 6.9 to get going on new unit tests. This is also how the original unit tests classes (under NB 6.7.1) were created.

A: 

This is driving me nuts!

It is worth noting that there is no actual error, the tests will run fine. It's just the editor that's messed up.

George Pauley
A: 

So you are importing from the same package as your unit test is in? There is a setting at

Tools -> Options -> Editor -> Hints -> Imports -> Import From The Same Package

That might be related. You could also check the options at Hints -> Dependency Scanning.

Jörn Horstmann
Hello Jorn, I found the options you suggested and tried them to no avail. Any other ideas?
stever
A: 

One of my co-workers figured it out.

Your Unit Tests needs a dependency on the package that it is testing. Unfortunately you cannot do this via the NetBeans GUI. But you CAN do this by directly editing the project.xml file directly. Here is an example the bold part is what I added.

... unit org.netbeans.libs.junit4 com.mycompany.mypackage

George Pauley
sigh, I can't make this format correctly. You need to add a <test-dependency> section that points to the package you want to test.
George Pauley
This was it. Fantastic. Caveats: you must not include the <recursive /> tag under <test-dependency> and you must include <compile-dependency />. This was the case with at least my particular migration and module.
stever