History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEA-16317
Type: Bug Bug
Status: Waiting for Reply Waiting for Reply
Assignee: Alexey Kudravtsev
Reporter: Mark Vedder
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Feedback

IDEA inappropriately throws an error that a JUnit 4 test "is not derived from TestCase"

Created: 13 Nov 07 01:27   Updated: 15 Jan 08 23:41
Component/s: Unit Testing. JUnit

File Attachments: None
Image Attachments:

1. screenshot-1.jpg
(4 kb)

Build: 7,523
Severity: Extreme


 Description  « Hide
I added a new test method to an existing JUnit4 test class. Upon trying to run the new JUnit test (via Ctrl+Shift+F10), the test did not run and IDEA reported the error "com.mycompany.MyUnitTest is not derived from TestCase. Do not provide method name." I can run any of the previously existing test methods individually (via Ctrl+Shift+F10), but not any new tests added to the class, including the simple test:
@Test
public void someTest()
{
    assertTrue(true);
}

I always get the "not derived" error. I can run all the test methods in the class (via Ctrl+Shift+F10 when the cursor is on the class' name), and the new tests run properly.

I, and others, have run into this issue previously (see IDEADEV-13219). I do not know what causes it to suddenly surface. Another user commented that it appears to happen if you accidentally create a test method that takes parameters. However, I am certain that I did not do that in this instance.

The issue can be resolved by shutting down IDEA and then deleting the entire content of the .IntelliJ70/system/caches directory. However this is not an acceptable workaround given how much of a productivity killer it is. When opening a project for the first time after clearing the cache, it takes 5-10 minutes (depending on the size of the project) for IDEA re-parse and cache the projects' content.



 All   Comments   Work Log   Change History      Sort Order:
Alexey Kudravtsev - 13 Nov 07 14:36
It seems you have Run configuration/Run make before launch checked off.
Since IDEA does not recompile the file before run, it cannot find the corresponding method.

Mark Vedder - 13 Nov 07 22:18
I do have "Make" in the "Before launch" section selected (i.e. it is checked), and typically do. Yesterday when I was experiencing the issue, I even deleted the IDEA out directory (i.e. the "Project Compiler Output" directory), did a full project rebuild (Build | Rebuild Project), and then tried running the JUnit test. I still received the "com.mycompany.MyUnitTest is not derived from TestCase. Do not provide method name." error. I tried this several times, and even tried renaming the test method, and the test class and then rebuilding. Nothing worked. It was only after I shut down IDEA, deleted the system cache, and restarted IDEA, and rebuilt the project, that the issue was resolved.

Also, if IDEA wasn't finding the compiled class (or at least the version of it with the new method), that wouldn't explain why the new test ran fine – and was listed in the list of tests run in the left side tree – when I ran all tests in the class. But then when I tried to run that new test by itself immediately afterwards, it still gave the error.


Mark Vedder - 14 Nov 07 22:01
FYI: I ran into this issue again today. But this time on a test that I had not modified. In fact, nothing in the test class had changed. I made a minor change in the tested class, and when I went to run the test for it, I received the "not derived" error. As before, while I can run all the tests in the class, I cannot run the individual test.

Alexey Kudravtsev - 16 Nov 07 16:53
You are running the test method via the Run configuration combobox in the IDEA toolbar, right?
Is the test method icon there is shown red-crossed, like in the acreenshot attached?

Mark Vedder - 21 Nov 07 00:16
>You are running the test method via the Run configuration combobox in the IDEA toolbar, right?
Sometimes. Frequently I simply hit Ctrl+Shift+F10 while my cursor is in the test method.
>Is the test method icon there is shown red-crossed, like in the screenshot attached?
No. They were showing as valid. That's the first thing I look at if I have trouble running a test.

I know this is a hard one to troubleshoot since it is very intermittent. And I have no way to reliably reproduce it for you. The next time it happens, is there anything I can grab for you? A log file or memory snapshot?


Alexey Kudravtsev - 21 Nov 07 15:16
Well, it seems the test class does not get recompiled on run.
Next time the thing occurs, could you please note the test source class timestamp, and the corresponding .class file timestamp (should be found in your compiler output directory)?
Thank you.
And BTW, you are not using Ant, aren't you?

Mark Vedder - 27 Nov 07 19:53
>And BTW, you are not using Ant, aren't you?

I do use Ant. But, the ant script copies all the sources to a new directory (for some token replacements) and compiles them to a different target directory than the 'out' directory that IDEA compiles to. That's done purposefully to prevent IDE caching problems (and because the Ant script does a clean build and deletes its output directory). So for all intents and purposes, IDEA's compiling and test runs are completely isolated from Ant's compiling and test runs.


Alexey Kudravtsev - 27 Nov 07 20:03
Is the test class compiled by Ant?
Is Ant target set up to run before make?

Mark Vedder - 28 Nov 07 08:04 - edited
>Is the test class compiled by Ant?
Only when I do a full build via Ant. But it is compiled into a different directory then when IDEA compiles a test class.
tool type src dir output dir
IDEA prod <project-root>/src/main/java <project-root>/out/production
  test <project-root>/src/test/java <project-root>/out/test
Ant prod <project root>/target/work/ant-src/main/java <project-root>/target/classes
  test <project root>/target/work/ant-src/test/java <project-root>/target/test-classes

>Is Ant target set up to run before make?
No

[Edit]
Also, the 'target' directory is set as an excluded directory, as is the 'out' directory.


Mark Vedder - 15 Jan 08 23:41
I ran into this again today. So as requested:

>Next time the thing occurs, could you please note the test source class timestamp, and the
>corresponding .class file timestamp (should be found in your compiler output directory)?

Both the .java source file and the .class file have a timestamp of 2008-01-15 15:26

However, I may have found a contributing factor to the issue.

My project comprises of several modules. Most of the modules do not change frequently. The one"primary" module is currently the one being heavily developed. I have a separate module defined for the TRUNK, and the various release branches. I do this since it is an easy way to handle branching. (We branch every month or two.) When a new branch is created, I can copy the TRUNK module definition, and place it in the new branch's directory:

<module-root>/TRUNK/moduleName-TRUNK.iml
<module-root>/TRUNK/src/main/java
<module-root>/TRUNK/src/test/java
<module-root>/TRUNK/ide-out/classes
<module-root>/TRUNK/ide-out/test-classes
<module-root>/RB1/moduleName-RB1.iml
<module-root>/RB1/src/main/java
<module-root>/RB1/src/test/java
<module-root>/RB1/ide-out/classes
<module-root>/RB1/ide-out/test-classes
<module-root>/RB2/moduleName-RB2.iml
<module-root>/RB2/src/main/java
<module-root>/RB2/src/test/java
<module-root>/RB2/ide-out/classes
<module-root>/RB2/ide-out/test-classes
etc

this allows me to have all my configurations of the release branch match the trunk at the time the release branch was created. Note that my compile target directories are different.

I then can add or remove a release branch IDEA module or the TRUNK module to the IDEA project as necessary. Sometimes I may have the TRUNK and a Release Branch module added to the project at the same time.

In this instance, when I received the error, I commented out an @Ignore annotation on a test on the Trunk. (It was for some functionality originally planned for the last release, but later postponed. So the ignored test is on the last release branch). After commenting out the @Igonre annotation, I tried to run that individual test via ctrl+shirt+F10 (with the cursor on the test name). It was then that I received the "not derived" error. (I then grabbed the timestamps shown above). I was able to successfully run all tests in the class (by having the cursor on the class name and hitting ctrl+shift+F10). But even after doing that, I could not run the individual test without getting the "not derived" error.

I then removed the release branch modules from the project, leaving only the TRUNK module. I then tried to run the individual test, and it ran successfully. I then added the release branch module back, and the test still ran fine. Note that I have worked, sometimes for several days or even weeks, with the TRUNK and a release branch module added/attached to the project.

So it might be that on some occasions the caching between the modules gets confused since each module (obviously) has identical classes. Is that possibly the issue?