7

I googled little bit and it seems for me that it's possible. But when I tried like this:

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

And "test" class:

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))
  }
}

I have an 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)

Can JMockit work with with scala? And if it can what am I doing wrong?

Moses
  • 1,243
  • 3
  • 14
  • 21
  • 4
    I tried JMockIt with Scala about a year ago without success. I'm not sure whether it can be done. JMockIt does a lot of byte code manipulation and I doubt it takes into account the sorts of tricks Scala utilizes in byte code. – joescii Mar 15 '14 at 12:55

1 Answers1

0

JMockit does not support Scala or any language other than Java on the JVM

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.

Novaterata
  • 4,356
  • 3
  • 29
  • 51