Eclipse 没有看到我的新 junit 测试

发布于 2024-08-28 01:26:07 字数 273 浏览 6 评论 0原文

我正在使用 eclipse 在单个 junit(4) 测试类中运行测试。课堂上的测试都运行得很好。然后我添加一个额外的测试,并通过再次在 ecplise 中运行的测试来运行该类。仅运行旧的测试。日食看不到新的测试。没有错误或任何东西,就好像 eclipse 正在查看旧版本的测试一样。

如果我使用 Maven 运行测试,一切都会正常。此外,在 maven 中运行测试后,eclipse 可以正确查看并运行新测试。

有什么想法吗?有什么想法如何让 ecplipse 的测试运行程序查看我的新测试用例吗?

I'm using eclipse to run the tests in a single junit(4) test class. The tests in the class all run just fine. Then I add an additional test and run the class through the test running in ecplise again. Only the old tests are run. The new test isn't seen by eclipse. There's no error or anything, it's just as if eclipse is looking at an old version of the test.

If I run the tests using maven, everything works fine. Additionally, after I run the tests in maven, ecplipse can see and run the new test correctly.

Any ideas what's going on? Any ideas how to get ecplipse's test runner to see my new test cases?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

缱倦旧时光 2024-09-04 01:26:08

也许您“只是”需要创建一个新的运行配置。 Eclipse 会“记住”最新使用的运行配置,如果没有另外告知,则只会重复它。为了确保您拥有新的运行配置,您可以右键单击包资源管理器中的测试用例,然后选择运行方式 |联合测试。下次您点击播放时,这将是“记住的”运行配置等。

Maybe you "just" need to create a new Run configuration. Eclipse "remembers" the latest used Run configuration and just repeats it if not told otherwise. To make sure you have a new Run Configuration you can rightclick the test case in the package explorer and choose Run As | Junit Test. Next time you hit play this will be the "remembered" Run configuration etc.

抠脚大汉 2024-09-04 01:26:08

您可能会发现这很可能是由于使用 Maven 构建造成的(Maven 通常构建到“目标”文件夹中),但 Eclipse 在其自己的构建过程中使用不同的构建文件夹。最简单的方法是进入 Eclipse 项目(如果使用 OSGi 则为 Bundle)下的目标文件夹,并从该目录下删除冲突的子文件夹/类文件;对我来说,这是我的“目标”文件夹。然后让 Eclipse 重建,一切都会好起来的。

从技术上讲,或者,如果您愿意,您可以直接删除整个 build/target 文件夹,然后让 Eclipse 重建所有内容。

You might find this is likely caused by using Maven to build (Maven usually builds into the 'target' folder), but Eclipse is using a different build folder for its own build process. Simplest way is to go into the target folder under your Eclipse Project (or Bundle if using OSGi) and delete the conflicting subfolders/class-files from under that directory; for me this is my "target" folder. Then get Eclipse to rebuild, and everything should be fine.

Technically, and alternatively, you could just blow away the entire build/target folder if you wanted to, and let Eclipse rebuild everything.

窝囊感情。 2024-09-04 01:26:08

为了响应 Ryan Dawe 提供的答案,我发现对于构建路径上的所有源文件夹,默认输出文件夹只能设置为一个文件夹。因此,如果我将输出文件夹更改为 target/test-classes,我的 src/main/java 也会在那里输出类。
您可能为不同的旧版本 eclipse 编写了此响应,但从 Mars.2 版本开始,我们只能为所有源文件夹设置一个默认输出文件夹。

到目前为止,我找到的解决此问题的最佳解决方案是仅将目标/测试类作为类文件夹包含在内,方法是转到“项目”->“项目”。属性-> Java 构建路径 ->图书馆 ->添加类文件夹。

In response to the answer provided by Ryan Dawe, I have found out that Default output folder can be set to only one folder, for all the source folders on build path. So if i changed the output folder to target/test-classes, my src/main/java was also outputting classes there.
You might have written this response for a different older version of eclipse, but as of Mars.2 release, we can only have one default output folder for all source folders.

The best solution i have found so far for this problem is to just include the target/test-classes as a class folder, by going to Project -> Properties -> Java Build Path -> Libraries -> Add Class folder.

牵你手 2024-09-04 01:26:08

看来您的项目没有重新编译。要么检查菜单:自动项目/构建,要么按照 Boris Pavlocic 的评论手动执行。

It seems that your project wasn't recompiled. Either check Menu:Project/Build Automatically or do it manually as Boris Pavlocic commented.

回忆追雨的时光 2024-09-04 01:26:08

这似乎与 junit not using the latest file 问题

相同似乎 Eclipse 将编译的测试放在错误的文件夹中,这可以通过手动指定它们应该结束的位置来解决。

This seems to be the same issue as junit not using the newest file

The problem seems to be that Eclipse puts the compiled tests in the wrong folder which can be solved by manually specifying where they should end up.

弥繁 2024-09-04 01:26:08

如果没有,请在测试类前面添加“test”,@Test 注释并不总是从 Eclipse 的 Junit Test 框架中获取。

Add "test" in front of your test classes if not there already the @Test annotation isn't always picked up from Eclipse's Junit Test framework.

挥剑断情 2024-09-04 01:26:08

这是我解决问题的方法...

  1. 右键单击项目并转到运行方式 ->运行配置...
  2. 选择JUnit -> [项目名称]出现在弹出窗口上
    ([project-name] 的这个配置是由 eclipse 为我创建的
    但如果没有,您可以右键单击 JUnit ->新建并创建它)
  3. 转到类路径选项卡,
  4. 突出显示用户条目,然后单击
  5. 高级选项上的 高级...按钮出现的弹出窗口选择添加文件夹,然后
  6. 在出现的文件夹选择弹出窗口中单击确定,滚动到打开的项目< strong>target 并选择 test-classes 并单击OK
  7. 对 [project-name]/target/classes 目录和任何其他目录重复步骤 4-6类路径中需要(如测试中使用的属性文件等)

注意:这假设您的项目的默认测试输出文件夹是 target/test-classes,如果不是,则进行相应调整。另外,请确保您在 JUnit 运行配置下选择了正确的 JUnit 版本,并且您的 src/test/java 目录是项目的源文件夹等,正如其他人提到的那样。

Here is how i fixed my problem...

  1. right click project and go to Run As -> Run Configurations...
  2. select JUnit -> [project-name] on the the popup that came up
    (this configuration of [project-name] was created for me by eclipse
    but if not there you can right click JUnit -> New and create it)
  3. goto Classpath tab
  4. highlight User Entries and click Advanced... button
  5. on the Advanced Options popup that came up select Add Folders and click OK
  6. on the Folder Selection popup that came up scroll to your project open up target and select test-classes and click OK
  7. repeat steps 4-6 for the [project-name]/target/classes directory and any other directory needed in your classpath (like properties files used in your tests etc.)

Note: this assumes your project's default output folder for tests is target/test-classes, if it is not then adjust accordingly. Also, make sure you have the right JUnit version selected under the JUnit Run Configuration as well and your src/test/java directory is a source folder to your project, etc. as mentioned by others.

黑色毁心梦 2024-09-04 01:26:08

这意味着您已经创建了一个尚未构建的测试类。
构建后,例如使用“gradle build”,Eclipse 也会找到 Test 类。
就我而言,我之前也必须进行清理。

It means that you have created a Test class that you haven´t build yet.
After a build, for example with "gradle build" the Test class will be found by Eclipse too.
In my case I had to make a cleanup before as well.

失眠症患者 2024-09-04 01:26:08

我将其添加到项目主目录中的 .classpath 中。

<classpathentry kind="src" output="target/test-classes" path="src/test/java">
    <attributes>
        <attribute name="test" value="true"/>
        <attribute name="optional" value="true"/>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>

I added this to my .classpath in the project's home directory.

<classpathentry kind="src" output="target/test-classes" path="src/test/java">
    <attributes>
        <attribute name="test" value="true"/>
        <attribute name="optional" value="true"/>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>
咿呀咿呀哟 2024-09-04 01:26:07

我有同样的问题。我通过执行以下操作解决了这个问题:

  • 转到项目 ->属性-> Java 构建路径
    对于源文件夹 src/test/java,输出文件夹设置为
    “默认输出文件夹”
  • 将其设置为 Maven 结构中典型的 Maven target/test-classes 目录

此后,Maven 和 Eclipse 保持同步(而不是 Eclipse 愉快地运行旧版本的测试) ,从最后一次 Maven 编译开始)。

I had the same issue. I solved it by doing the following:

  • Going to Project -> Properties -> Java Build Path
    For the source folder src/test/java, the output folder was set to
    "Default output folder"
  • Setting this to the typical Maven target/test-classes directory in your Maven structure

After this, Maven and Eclipse were in sync (as opposed to Eclipse happily running an older version of the tests, from whenever the last Maven compile was).

坏尐絯℡ 2024-09-04 01:26:07

可能 src/test 不在 Java 构建路径中。

开普勒解决方案:

Project ->构建路径->配置构建路径->来源->添加文件夹

然后勾选srctest对应的框

Possibly src/test is not in the Java Build Path.

Solution on Kepler:

Project -> Build Path -> Configure Build Path -> Source -> Add Folder

Then check the box corresponding to test under src

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文