我用Google搜索了一下,对我而言,这似乎是可能的.但是当我尝试这样的时候:
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))
}
}
我有一个例外:
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.