Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I run all Java JUnit Tests from Package Explorer? - Scala Plugin Issue

Edit 3

I installed a new version of eclipse (Mars - 4.5.0), and everything works. However, when I reinstall Scala via the Eclipse Marketplace, the issue reappeared. So perhaps it's something with the scala plugin?


EDIT 2

I was playing around with it more and found that if I delete certain packages, the functionality returns. Specifically, if I delete packages functional and io, the ability to run the whole project's testing returns. Renaming the packages does not help, only deleting them. Furthermore, if I add JUnit tests in those packages, I am still unable to run that test via the package explorer by running the whole package.


I'm having an issue with a particular Java project in Eclipse. When I attempt to run all JUnit tests from the project explorer (via [right click on project folder] --> run as --> JUnit Test), I get the error message a lot of people seem to be seeing:

Problem Launching JUnit Tests: No tests found with test runner 'JUnit 4'

Clicking OK on the message brings up the Run configurations dialogue.

What's strange is that the problem seems very isolated to this project at full project scope. I am able to do the following without trouble:

  • Run any single test within this project by opening it and clicking the green run button at top.
  • Run any single test within this project by right clicking on the class within the project explorer and selecting run as JUnit Test
  • Run all tests within any package within this project by the same method.
  • Run all tests within any other project by the same method.

I've tried the standard stuff mentioned in similar posts, nothing seems to work. Specifically, I've tried:

  • Restarting eclipse
  • Restarting my computer
  • Cleaning and rebuilding the project
  • Deleting the project and recloning from git, then re-adding to eclipse
  • Adding the @RunWith annotation to my test cases
  • Making sure all of my test cases start with "test"
  • Using JUnit3 instead
  • Deleting all JUnit run configurations and recreating this run configuration

Additionally, I distinctly remember this functionality working a little while ago for this project, but don't remember exactly when. So I must have added/changed/deleted something that has caused the error to appear.


EDIT @ Durron597's suggestions: None of the suggestions worked, unfortunately. I also tried deleting every JUnit run configuration and trying the create configuration process again, still no luck.

My eclipse version is: Luna Service Release 2 (4.4.2)

My JUnit version is: 4.11

JUnit preferences screenshot: JUnit preferences screenshot


Here's the code from one test:

package common;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashSet;

import org.junit.Test;

public class UtilTest {

    @Test
    public void testWrappers(){
        short[] s = {1,2,3,4};
        Short[] s2 = Util.boxArr(s);
        short[] s3 = Util.unboxArr(s2);

        assertEquals(s.length, s2.length);
        assertEquals(s.length, s3.length);
        for(int i = 0; i < s.length; i++){
            assertEquals(s[i], s2[i].shortValue());
            assertEquals(s[i], s3[i]);
        }

        int[] i = {1,2,3,4, Integer.MAX_VALUE, Integer.MIN_VALUE};
        Integer[] i2 = Util.boxArr(i);
        int[] i3 = Util.unboxArr(i2);

        assertEquals(i.length, i2.length);
        assertEquals(i.length, i3.length);
        for(int x = 0; x < s.length; x++){
            assertEquals(i[x], i2[x].intValue());
            assertEquals(i[x], i3[x]);
        }

        long[] l = {1,2,3,4, Integer.MAX_VALUE, Integer.MIN_VALUE, Long.MAX_VALUE, Long.MIN_VALUE};
        Long[] l2 = Util.boxArr(l);
        long[] l3 = Util.unboxArr(l2);

        assertEquals(l.length, l2.length);
        assertEquals(l.length, l3.length);
        for(int x = 0; x < s.length; x++){
            assertEquals(l[x], l2[x].longValue());
            assertEquals(l[x], l3[x]);
        }

        float[] f = {1,2,3,4, 0.4f, 0.1f, Float.MAX_VALUE, Float.MIN_NORMAL};
        Float[] f2 = Util.boxArr(f);
        float[] f3 = Util.unboxArr(f2);

        assertEquals(f.length, f2.length);
        assertEquals(f.length, f3.length);
        for(int x = 0; x < s.length; x++){
            assertEquals(f[x], f2[x].floatValue(), 0.00001);
            assertEquals(f[x], f3[x], 0.00001);
        }


        double[] d = {1,2,3,4, 0.4, 0.1, Float.MAX_VALUE, Float.MIN_VALUE, Double.MAX_VALUE, Double.MIN_NORMAL};
        Double[] d2 = Util.boxArr(d);
        double[] d3 = Util.unboxArr(d2);

        assertEquals(d.length, d2.length);
        assertEquals(d.length, d3.length);
        for(int x = 0; x < s.length; x++){
            assertEquals(d[x], d2[x].doubleValue(), 0.00001);
            assertEquals(d[x], d3[x], 0.00001);
        }

        char[] c = {1,2,3,4, 'a', 'b', '.', Character.MAX_VALUE, Character.MIN_VALUE};
        Character[] c2 = Util.boxArr(c);
        char[] c3 = Util.unboxArr(c2);

        assertEquals(c.length, c2.length);
        assertEquals(c.length, c3.length);
        for(int x = 0; x < s.length; x++){
            assertEquals(c[x], c2[x].charValue());
            assertEquals(c[x], c3[x]);
        }
    }

    @Test
    public void testRandElement(){
        assertTrue(null==Util.randomElement(null));

        HashSet<Integer> s = new HashSet<>();
        assertTrue(null==Util.randomElement(s));

        for(int i = 0; i < 10; i++){
            s.add(i);
        }

        HashSet<Integer> s2 = new HashSet<>();
        while(! s2.equals(s)){
            Integer i = Util.randomElement(s);
            s2.add(i);
            assertTrue(s.contains(i));
        }
    }

    @Test
    public void testPermute(){
        ArrayList<Integer[]> a = Util.permute(new Integer[]{1,2,3,4});
        assertEquals(a.size(), 24);

        for(Integer[] i : a){
            assertEquals(i.length, 4);
            assertEquals(10, i[0] + i[1] + i[2] + i[3]);
        }

        HashSet<Integer[]> s = new HashSet<>(a);
        assertEquals(s.size(), 24);

        a = Util.permute(new Integer[]{});
        assertEquals(a.size(), 1);
    }

}

The whole project is at https://github.com/Mshnik/UsefulThings if that helps as well.

like image 601
Mshnik Avatar asked Sep 28 '22 03:09

Mshnik


1 Answers

Try looking at the suggestions in this thread. It's not the same exact error but it's similar: No tests found with test runner 'JUnit 4'


I'm assuming the problem is that you don't have a proper Run Configuration for "Run all tests". This could have broken if you've recently cleaned out old and obsolete Run Configurations, and deleted the appropriate one without realizing it. Let's create one, by following these steps:

  1. Go to the Run configurations dialog.
  2. Select JUnit on the left hand side
  3. Click the page with the star, with tooltip text "New launch configuration"
  4. Give it a name. (I use AllTests)
  5. Click on the Run all tests in the selected project, package or source folder: radio button
  6. Use the search dialog box to point to your project
  7. Make sure Test runner is set to JUnit 4

Click Apply and then Run. This should restore the broken method.

If these steps don't work, try the following (try each one in order, then go to the next if it didn't fix it) - the idea being that perhaps you do have a configuration, but it's corrupted.

  1. Make sure you are using the Eclipse JUnit launcher at the bottom of that page
  2. Check all the other Run configurations that have the "Run all tests" radio button selected and delete them.
  3. Restart Eclipse
    • Do this last because I doubt it will do anything unless you've done the previous steps first, as you mention in your question

It should now be fixed. If it is not, please edit your question to include your version of JUnit and your version of Eclipse.

like image 160
durron597 Avatar answered Nov 15 '22 07:11

durron597