gpt4 book ai didi

scala - JMockit 可以与 Scala 一起使用吗?

转载 作者:行者123 更新时间:2023-12-04 12:58:32 26 4
gpt4 key购买 nike

我用谷歌搜索了一下,在我看来这是可能的。但是当我这样尝试时:

class Calc {
def sum(first: Int, second: Int) = {
first + second
}
}

和“测试”类:
class CalcTest {
@Test
def testSum(@Mocked test: Calc) {
new NonStrictExpectations() {{
test.sum(2, 3)
times = 1
result = Int.box(5)
}}
Assert.assertEquals(5, test.sum(2, 3))
}
}

我有一个异常(exception):

java.lang.IllegalAccessError: tried to access class mockit.Invocations from class com.kvg.client.CalcTest$$anon$1 at com.kvg.client.CalcTest$$anon$1.(CalcTest.scala:11) at com.kvg.client.CalcTest.testSum(CalcTest.scala:9) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)



JMockit 可以与 Scala 一起使用吗?如果可以的话,我做错了什么?

最佳答案

JMockit 在 JVM 上不支持 Scala 或除 Java 以外的任何语言

https://github.com/jmockit/jmockit1/pull/358

Finally, there were already requests in the past to add support for other JVM languages. I remember of Scala (ScalaMock), Extend, and Kotlin. If Groovy support was accepted, how to deny support for other languages? And keeping in mind that the JMockit project never intended to support anything other than the JVM (ie, not stuff like Dalvik) and the Java language.

关于scala - JMockit 可以与 Scala 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22423348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com