mockito/mockito-scala

Exception during macro expansion in mockito-scala-scalatest

raksit31667 opened this issue · 5 comments

Context (Environment)

Running unit tests with following dependencies:

  • Scala v2.11.12
  • Gradle v5.6
  • mockito-scala-scalatest_2.11 v1.14.3
  • scalatest_2.11 v3.0.5
  • spark-sql_2.11 v2.4.3

Here is the test script:

import org.mockito.scalatest.MockitoSugar

class MyTest extends FunSuite with MockitoSugar {

  test("should return something") {
    // given
    val mySpy = spy(new MySpy)
    when(mySpy.doSomething(any, any)).thenReturn(new DataFrame(...))

    // when
    val actual = mySpy.myMethod("some-string")

    // then
    val expected = new DataFrame(...)
    assert(expected === actual)

Expected Behavior

Tests should be running without any exceptions thrown.

Current Behavior

Failed to load ApplicationContext while initializing embedded database.

Error:(43, 11) exception during macro expansion: 
java.lang.NoSuchMethodError: org.scalactic.BooleanMacro.<init>(Lscala/reflect/macros/whitebox/Context;Ljava/lang/String;)V
	at org.scalatest.AssertionsMacro$.assert(AssertionsMacro.scala:34)
    assert(expected === actual)

Assumption

Dependency conflicts

That's weird, the old syntax doesn't use any macros, so I don't think is a mockito problem per-se.

In any case, I'm not a spark guy, I can take a look, but I'd need if you can put together a small github project that reproduces the issue.

Thanks!

@bbonanno Here is my small project

https://github.com/raksit31667/example-spark-gradle/tree/mockito-scala-issue

Thank you for your support, appreciated.

you'r assumption was right, you're using an old version of Scalatest, update to "3.1.2" and the problem goes away

The issue was resolved after upgrading to v3.1.2.

If you are Spark guys, and using holdenk/spark-testing-base, they are still depending on scalatest v3.0.5.

Please follow this pull request holdenk/spark-testing-base#320

I just wanted to add my resolution to this issue when changing from strictly mockito-core to mockito-scala. I had to add "org.scalactic" %% "scalactic" % "3.0.3" % "test" to my dependencyOverrides. I am not currently able to update scalatest past 3.0.4 and am on scala version 2.11.12