简体   繁体   English

为什么我不能从Package Explorer运行所有Java JUnit测试? - Scala插件问题

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

Edit 3 编辑3

I installed a new version of eclipse (Mars - 4.5.0), and everything works. 我安装了新版本的eclipse(Mars - 4.5.0),一切正常。 However, when I reinstall Scala via the Eclipse Marketplace, the issue reappeared. 但是,当我通过Eclipse Marketplace重新安装Scala时,问题再次出现。 So perhaps it's something with the scala plugin? 那么也许它是scala插件的东西?


EDIT 2 编辑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. 具体来说,如果我删除包functional and io ,则运行整个项目测试的能力将返回。 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. 此外,如果我在这些包中添加JUnit测试,我仍然无法通过运行整个包通过包浏览器运行该测试。


I'm having an issue with a particular Java project in Eclipse. 我在Eclipse中遇到了一个特定Java项目的问题。 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: 当我尝试从项目浏览器运行所有JUnit测试时(通过[right click on project folder] --> run as --> JUnit Test ),我收到许多人似乎看到的错误消息:

Problem Launching JUnit Tests: No tests found with test runner 'JUnit 4' 问题启动JUnit测试:测试运行'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作为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 重启eclipse
  • Restarting my computer 重新启动我的电脑
  • Cleaning and rebuilding the project 清理和重建项目
  • Deleting the project and recloning from git, then re-adding to eclipse 删除项目并从git重新克隆,然后重新添加到eclipse
  • Adding the @RunWith annotation to my test cases 将@RunWith注释添加到我的测试用例中
  • Making sure all of my test cases start with "test" 确保我的所有测试用例都以“test”开头
  • Using JUnit3 instead 而是使用JUnit3
  • Deleting all JUnit run configurations and recreating this run configuration 删除所有JUnit运行配置并重新创建此运行配置

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. 编辑@ Durron597的建议:不幸的是,没有任何建议有效。 I also tried deleting every JUnit run configuration and trying the create configuration process again, still no luck. 我还尝试删除每个JUnit运行配置并再次尝试创建配置过程,仍然没有运气。

My eclipse version is: Luna Service Release 2 (4.4.2) 我的eclipse版本是:Luna Service Release 2(4.4.2)

My JUnit version is: 4.11 我的JUnit版本是:4.11

JUnit preferences screenshot: JUnit首选项截图: JUnit首选项截图


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. 整个项目在https://github.com/Mshnik/UsefulThings,如果这也有帮助。

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' 这不是完全相同的错误,但它是相似的: 没有测试运行'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 选择左侧的JUnit
  3. Click the page with the star, with tooltip text "New launch configuration" 单击带有星号的页面,工具提示文本为“新启动配置”
  4. Give it a name. 给它起个名字。 (I use AllTests ) (我使用AllTests
  5. Click on the Run all tests in the selected project, package or source folder: radio button 单击Run all tests in the selected project, package or source folder:Run all tests in the selected project, package or source folder:单选按钮
  6. Use the search dialog box to point to your project 使用搜索对话框指向您的项目
  7. Make sure Test runner is set to JUnit 4 确保Test runner设置为JUnit 4

Click Apply and then Run. 单击Apply,然后单击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 确保您使用该页面底部的Eclipse JUnit启动程序
  2. Check all the other Run configurations that have the "Run all tests" radio button selected and delete them. 检查选中“运行所有测试”单选按钮的所有其他运行配置并删除它们。
  3. Restart Eclipse 重启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. 如果不是,请编辑您的问题以包含您的JUnit版本和您的Eclipse版本。

I updated to the most recent version of eclipse (Mars - 4.5.0), and the problem disappeared entirely. 我更新到最新版的eclipse(Mars - 4.5.0),问题完全消失了。 So perhaps it's a bug with the version of eclipse or the like. 所以也许这是eclipse等版本的错误。 Doesn't really answer why I had the issue to being with though. 我真的没有回答为什么我有这个问题。

If you look in the Problems tab, you might see a entry that states "scala tests not built due to errors in dependent scope(s) main" or something similar. 如果查看“问题”选项卡,您可能会看到一个条目,指出“scala测试不是由于依赖范围主要的错误而构建的”或类似的东西。 This indicates that some build problem with something in the classpath of the test prevented the tests from being built, even if your test does not depend on the broken piece itself. 这表明测试的类路径中的某些构建问题阻止了测试的构建,即使您的测试不依赖于损坏的部分本身。 It seems that the Scala compiler is a bit picky. 似乎Scala编译器有点挑剔。

In any case, fix the build problem and other parts of your package your tests will likely work. 在任何情况下,修复构建问题和包的其他部分,您的测试可能会起作用。 For me, I had a similar issue where the Scala Library container provided by the ScalaIDE did not contain Jackson Module Scala, and I had to add that library manually. 对我来说,我有一个类似的问题,ScalaIDE提供的Scala Library容器不包含Jackson Module Scala,我不得不手动添加该库。 Once I did so, this fixed the build and allowed me to run tests again. 一旦我这样做,这就修复了构建并允许我再次运行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM