如何使Eclipse检测Scala JUnit测试,其中包不匹配文件夹? [英] How can I make Eclipse detect Scala JUnit tests where package doesn't match folder?

查看:205
本文介绍了如何使Eclipse检测Scala JUnit测试,其中包不匹配文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Scala中,软件包不一定需要匹配文件夹。如果工具不关心,我宁愿放弃包装中冗长的组织前缀,以允许更浅的路径。

In Scala, packages doesn't necessarily need to match folders. And if tooling wasn't concerned I would rather leave out the ever so redundant organisation prefix of the package to allow for shallower paths.

我的问题是Eclipse JUnit插件似乎正在使用文件夹,而不是类路径。当我将Scala测试类放在与包中匹配的文件夹中时,一切正常。如果我把它放在我想要得到ClassNotFoundException的方式。

My problem is that the Eclipse JUnit plugin seems to be working with folders rather than classpath. When I place my Scala test classes in folders matching the package everything works fine. If I however put them the way I would like I get a ClassNotFoundException.

说我的包前缀是项目中所有类的org.myorganisation.myproduct。然后我想像

Say my package prefix is org.myorganisation.myproduct for all classes in a project. Then I would like to have folders like

src/test/scala/domainpackage1/

而不是

src/test/scala/org/myorganisation/myproduct/domainpackage1

但是如果我把一个测试类看起来像:

but if I put a test class looking like:

package org.myorganisation.myproduct;
package domainpackage1
...
@RunWith(classOf[JUnitRunner])
class DomainClass1Spec extends FeatureSpec with GivenWhenThen {
...
}

在文件夹中

src/test/scala/domainpackage1

我得到一个

java.lang.ClassNotFoundException: domainpackage1.DomainClass1Spec

所以似乎JUnit插件正在查看源位置,并寻找一个匹配的类文件,而不是以更稳定的方式查找该类。

So it seems the JUnit plugin is looking at the source location and looks for a class file matching that rather than finding the class in a more stable way.

我的意思是,应该可以从编译单元(.scala)中的当前位置找到输出(.class),对吗?

I mean, it should be possible to find the output (.class) from the current position in the compilation unit (.scala), right?

推荐答案

这是Eclipse中的一个已知问题:

This is a known issue in Eclipse:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=16209

已标记作为 WONTFIX 。但也许您应该对此发表评论,并指出Scala的问题。

It's marked as WONTFIX. But perhaps you should comment on it and point out the issue for Scala...

这篇关于如何使Eclipse检测Scala JUnit测试,其中包不匹配文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆