Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 221525

Summary: [JUnit] No tests found when sub-packages should be run
Product: [Eclipse Project] JDT Reporter: Neale Upstone <neale>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: minor    
Priority: P3 CC: martinae
Version: 3.3.2   
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard:

Description Neale Upstone CLA 2008-03-05 10:24:13 EST
(Also see Bug #139905)

If I select the root of the src (or in my case, test) source folder, right click, Run as->JUnit Test, then all my tests run.

If, however I want to run tests within a package tree, I get "no tests found with test runner 'JUnit 3'" (also for JUnit 4).

This is inconsistent behaviour, for several reasons:
- Running the default package does run all tests in all sub-packages
- The UI for editing test case launchers allows me to select a package that the runner then ignores.

Personally, this is irritating as I have tests broken into on-change, nightly and release tests, which are easiest to sub-divide by package.

I suspect that the fix for this is trivial, as the case does work for the default package.
Comment 1 Martin Aeschlimann CLA 2008-03-11 11:19:23 EDT
I tried to reproduce, but this seems to wrk for me:

- create a new project with JUnit 3 on the classpath 
  and a source folder 'src'
- create the following 3 test cases in 'src'

package a;
import junit.framework.TestCase;
public class A extends TestCase {
	public void testFoo() throws Exception {
	}
}
//----------------------
package a;
import junit.framework.TestCase;
public class R extends TestCase {
	public void testFoo() throws Exception {
	}
}
//----------------------
package b;
import junit.framework.TestCase;
public class B extends TestCase {
	public void testFoo() throws Exception {
	}
}

- select 'src', 'Run as JUnit Test': 3 tests run
- select package 'a', 'Run as JUnit Test': 2 tests run
- select package 'b', 'Run as JUnit Test': 1 test run

Can you add a reproducible case ?
Comment 2 Neale Upstone CLA 2008-03-11 11:40:41 EDT
Modifying your example, the following is the minimum:

- create a new project with JUnit 3 on the classpath 
  and a source folder 'src'
- create the following 3 test cases in 'src'

package org.eclipse;
import junit.framework.TestCase;
public class A extends TestCase {
        public void testFoo() throws Exception {
        }
}

- In Package Explorer's menu, set Package Presentation -> Hierarchical

- select 'src', 'Run as JUnit Test': 1 test runs

- select package 'org', 'Run as JUnit Test': Get error: 
       "no tests found with test runner 'JUnit 3'"

- select package 'org.eclipse', 'Run as JUnit Test': 1 test runs

Comment 3 Martin Aeschlimann CLA 2008-03-11 13:23:04 EDT
OK, now I understand what you mean.

The hierarchical mode is only a view.

Actions always work on the model hierarchy. That's the same for all actions and all views.


Comment 4 Neale Upstone CLA 2008-03-11 13:44:39 EDT
Ok.  I understand that you probably have Project -> *Package as a model relationship, and if so, this should be reflected in the UI:

The following are therefore bugs: 

- The UI for editing test case launchers allows me to select a package that the
runner then ignores.
- Run As -> JUnit Test, should not be available for a path, *unless* that path is a package.

In both cases, the launch configuration should not be created without, at the very least, informing the user that there are no classes in the specified package.
Comment 5 Martin Aeschlimann CLA 2008-03-12 06:58:18 EDT
In your structure  'org' and 'eclipse' are both packages. 'org' happens to be empty.
It could also be that 'eclipse' is empty or contains some Java files but doesn't contain any tests. This is more expensive to find out.

I added a filter in the JUnit launch config dialog and the shortcut to avoid empty packages (released > 20080312)
Comment 6 Neale Upstone CLA 2008-03-12 09:59:50 EDT
Sounds like a tick in the box for the "out of the box experience" theme.

Thanks.
Also, I've corrected the reported version, now that 3.3.2 has been made available in the versions box ;)