scalatest 和 SBT 问题 -- 类不是可访问的 org.scalatest.Suite
使用 SBT 运行测试时,我的代码修订版 5 出现错误:
https://www.assembla.com/code/opyate-scala-graph-fork-sbt/subversion/changesets/5
我在互联网上搜索了“Class is不是可访问的 org.scalatest.Suite", 但仅在 scalatest 框架代码中获取该消息的结果。
请帮助我找出问题所在,是否是依赖版本问题、兼容性问题,或者测试编码是否不正确。
详细信息如下(一个示例):
套件
@RunWith(classOf[JUnitRunner])
class TDegreeRootTest
extends Suites(
new TDegree[immutable.Graph](immutable.Graph),
new TDegree[ mutable.Graph]( mutable.Graph))
with ShouldMatchers
{
}
测试类
class TDegree[+CC[N,E[X] <: EdgeLikeIn[X]] <: Graph[N,E] with GraphLike[N,E,CC[N,E]]]
(val factory: GraphCompanion[CC])
extends Suite
with ShouldMatchers
{ ... }
异常
[error] Could not run test scalax.collection.TDegree:
java.lang.IllegalArgumentException:
Class is not an accessible org.scalatest.Suite:
scalax.collection.TDegree
抛出异常的ScalaTest代码
以下需要为 clazz
我的 TDegree
实例保留 true
:
classOf[Suite].isAssignableFrom(clazz) &&
Modifier.isPublic(clazz.getModifiers) &&
!Modifier.isAbstract(clazz.getModifiers) &&
Modifier.isPublic(clazz.getConstructor(emptyClassArray: _*).getModifiers)
它需要一个无参构造函数,而我没有。< /em>
我想现在的问题变成了“我如何进行测试如果我的类没有无参构造函数,是否可以使用 ScalaTest 运行类?”。
Revision 5 of my code has an error when running the tests using SBT:
https://www.assembla.com/code/opyate-scala-graph-fork-sbt/subversion/changesets/5
I've searched the Interwebs for "Class is not an accessible org.scalatest.Suite", but only get results to that message in the scalatest framework code.
Please help me figure out what wrong and if it's a dependency version issue, a compatibility issue, or if the tests are just coded incorrectly.
The details are (one example):
Suites
@RunWith(classOf[JUnitRunner])
class TDegreeRootTest
extends Suites(
new TDegree[immutable.Graph](immutable.Graph),
new TDegree[ mutable.Graph]( mutable.Graph))
with ShouldMatchers
{
}
Test class
class TDegree[+CC[N,E[X] <: EdgeLikeIn[X]] <: Graph[N,E] with GraphLike[N,E,CC[N,E]]]
(val factory: GraphCompanion[CC])
extends Suite
with ShouldMatchers
{ ... }
The exception
[error] Could not run test scalax.collection.TDegree:
java.lang.IllegalArgumentException:
Class is not an accessible org.scalatest.Suite:
scalax.collection.TDegree
ScalaTest code that throws exception
The following needs to hold true
for clazz
an instance of my TDegree
:
classOf[Suite].isAssignableFrom(clazz) &&
Modifier.isPublic(clazz.getModifiers) &&
!Modifier.isAbstract(clazz.getModifiers) &&
Modifier.isPublic(clazz.getConstructor(emptyClassArray: _*).getModifiers)
It requires a no-argument constructor, which I don't have.
I guess the question now becomes "How do I get my test classes to run with ScalaTest if my classes do not have a non-argument constructor?".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这意味着 sbt 正在发现并交给 ScalaTest 一个不是可访问套件的类。这可能意味着它是包访问。如果它是公共的,请确保它有一个公共的无参数构造函数。我会快速查看差异,看看是否能找到罪魁祸首。
What that means is that sbt is discovering and handing to ScalaTest a class that is not an accessible suite. That probably means it is package access. If it is public, make sure it has a public no-arg constructor. I'll look at the diffs real quick to see if I can see the culprit.