Finatra IntegrationTest failed with "object TwitterModule is not a member of package com.twitter.inject"

314 views Asked by At

I got a problem when implementing IntegrationTest with Finatra on Scala. I'm just following their official docs for early implementation, but I got error

[error] D:\Workspace\OpenSource\kanca-api\src\test\scala\io\kanca\GraphTestModule.scala:4:8: object TwitterModule is not a member of package com.twitter.inject
[error] import com.twitter.inject.TwitterModule
[error]        ^
[error] D:\Workspace\OpenSource\kanca-api\src\test\scala\io\kanca\GraphTestModule.scala:7:32: not found: type TwitterModule
[error] object GraphTestModule extends TwitterModule {
[error]                                ^

Here is my module

import com.google.inject.{Provides, Singleton}
import com.twitter.inject.TwitterModule
import io.kanca.fbgraph.Graph

object GraphTestModule extends TwitterModule {

  @Singleton
  @Provides
  def providesGraph: Graph = new Graph

}

And here is my test suite

import com.twitter.inject.IntegrationTest
import com.twitter.inject.app.TestInjector

class MySQLSpec extends IntegrationTest {

  def injector =
    TestInjector(
      modules =
        Seq(GraphTestModule))
      .create

  val graph = injector.instance[Graph]

  ...
}

If you want to look at the full source code, here it is https://github.com/hellowin/kanca-api/tree/try-module simply run sbt test. For comparison, look at master branch, which I don't implement DI yet and it works perfectly.

What's wrong with my implementation?

1

There are 1 answers

0
Andi N. Dirgantara On

I've solve it, basically it's because of missing TestDependencies on build.sbt. I tried with this dependencies, and all went well.

"com.twitter" %% "finatra-http" % versions.twitter % Test classifier "tests",
"com.twitter" %% "inject-app" % versions.twitter,
"com.twitter" %% "inject-app" % versions.twitter % Test classifier "tests",
"com.twitter" %% "inject-core" % versions.twitter,
"com.twitter" %% "inject-core" % versions.twitter % Test classifier "tests",
"com.twitter" %% "inject-modules" % versions.twitter,
"com.twitter" %% "inject-modules" % versions.twitter % Test classifier "tests",
"com.twitter" %% "inject-server" % versions.twitter,
"com.twitter" %% "inject-server" % versions.twitter % Test classifier "tests",
"com.twitter" %% "inject-utils" % versions.twitter,
"com.twitter" %% "inject-utils" % versions.twitter % Test,
"org.mockito" % "mockito-all" % versions.mockito,
"org.mockito" % "mockito-all" % versions.mockito % Test,
"org.specs2" %% "specs2-mock" % versions.specs2,
"org.specs2" %% "specs2-mock" % versions.specs2 % Test,
"com.google.inject.extensions" % "guice-testlib" % versions.guice % Test,
"com.google.inject.extensions" % "guice-testlib" % versions.guice % Test classifier "tests",

Here is my own PR https://github.com/hellowin/kanca-api/pull/3/files