Why can't I run all Java JUnit tests from the package explorer? - Scala plugin problem

Edit 3

I installed the new version of eclipse (Mars - 4.5.0) and everything works. However, when I reinstall Scala through the Eclipse Marketplace, the problem reappears. Maybe this is something with the Scala plugin?


EDIT 2

I talked more with him and found that if I delete certain packages, the functionality will return. In particular, if I remove the functional and io packages, the ability to run all the testing of the project returns. Renaming packages does not help, just removing them. Also, if I add JUnit tests to these packages, I still cannot run this test through the package explorer by running the whole package.


I am having a problem with a specific Java project in Eclipse. When I try to run all JUnit tests from the project explorer (via [right click on project folder] --> run as --> JUnit Test ), I get an error message that many people see:

Problem Running JUnit tests: No tests found with test runner "JUnit 4"

When you click "OK" in the message, the dialog "Run configuration" appears.

What is strange is that the problem seems very isolated from this project with the full implementation of the project. I can do the following without problems:

  • Run any single test in this project by opening it and clicking the green launch button at the top.
  • Run any single test in this project by right-clicking on a class in the project explorer and choosing to run as JUnit Test
  • Run all the tests in any package inside this project using the same method.
  • Run all tests in any other project using the same method.

I tried the standard materials mentioned in similar posts, nothing works. In particular, I tried:

  • Restart eclipse
  • Rebooting my computer.
  • Project cleanup and restoration
  • Removing a project and repeating from git and then re-adding to eclipse
  • Adding @RunWith annotation to my test cases
  • Make sure all my test cases start with a “test”
  • Using JUnit3 instead
  • Removing all JUnit startup configurations and re-creating this startup configuration

In addition, I clearly remember this functionality, which worked some time ago for this project, but I don’t remember exactly when. So I have to add / modify / delete something that caused the error.


EDIT recommendations @ Durron597: Unfortunately, none of the suggestions worked. I also tried removing every JUnit startup configuration and trying to create the setup process again, but still no luck.

My eclipse version: Luna Service Release 2 (4.4.2)

My JUnit Version: 4.11

JUnit screenshot settings: JUnit Screen Settings


Here is 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.

+5
source share
3 answers

Try looking at the suggestions in this thread. This is not the same exact error, but it is similar: No tests with JUnit 4 test runner


I assume the problem is that you do not have the proper launch configuration for "Run all tests." This can break if you recently cleaned up old and outdated startup configurations and deleted the corresponding one without realizing it. Create it by following these steps:

  • Go to the "Run Configuration" dialog.
  • Select JUnit on the left side
  • Click on the star page with the tooltip text "New launch configuration"
  • Give him a name. (I use AllTests )
  • Click the Run all tests in the selected project, package or source folder: switch Run all tests in the selected project, package or source folder:
  • Use the search dialog to point to your project.
  • Make sure Test runner set to JUnit 4

Click Apply, and then Run. This should repair the failed method.

If these steps do not work, try the following (try each in order, then move on to the next if it does not fix it) - the idea is that you may have a configuration, but it is corrupted.

  • Make sure you use the Eclipse JUnit Launcher at the bottom of this page.
  • Check all other launch configurations in which the Run All Tests radio button is selected and delete them.
  • Restart eclipse
    • Make it last because I doubt he will do anything if you did not take the previous steps first, as you mentioned in your question

Now it should be fixed. If this is not the case, please edit your question to include your version of JUnit and your version of Eclipse.

+3
source

I upgraded to the latest version of eclipse (Mars - 4.5.0) and the problem completely disappeared. So maybe this is a bug with the eclipse version or the like. In fact, I do not answer why I had a problem with being with.

+1
source

If you look at the “Problems” tab, you can see the entry that says: “scala tests were not built due to errors in the dependent area (s) main” or something like that. This indicates that some build problem with something along the way to the test class prevented the creation of tests, even if your test does not depend on the broken element itself. It seems that the Scala compiler is a bit picky.

In any case, fix the build problem and other parts of your package, your tests are likely to work. For me, I had a similar problem when the Scala Library container provided by ScalaIDE did not contain the Jackson Module Scala, and I had to add this library manually. As soon as I did this, it fixed the build and allowed me to run the tests again.

0
source

All Articles