Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception during macro expansion in mockito-scala-scalatest #246

Closed
raksit31667 opened this issue May 29, 2020 · 5 comments
Closed

Exception during macro expansion in mockito-scala-scalatest #246

raksit31667 opened this issue May 29, 2020 · 5 comments

Comments

@raksit31667
Copy link

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

@ultrasecreth
Copy link
Member

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!

@raksit31667
Copy link
Author

@bbonanno Here is my small project

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

Thank you for your support, appreciated.

@ultrasecreth
Copy link
Member

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

@raksit31667
Copy link
Author

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

@goytia54
Copy link

goytia54 commented Mar 2, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants