Integration Tests

Whereas Feature Tests start a server or app under test (thereby loading its entire object graph), integration tests generally only test across a few interfaces in the system. In Finatra, we provide the c.t.inject.app.TestInjector which allows you to pass it a set of modules and flags to construct a minimal object graph.

To write an integration test, extend the c.t.inject.IntegrationTest trait. Then override the injector val with your constructed instance of c.t.inject.app.TestInjector. You’ll then be able to access instances of necessary classes to execute tests.

import com.twitter.inject.IntegrationTest

class ExampleIntegrationTest extends IntegrationTest {
  override val injector =
    TestInjector(
      flags =
        Map("foo.flag" -> "meaningfulValue"),
      modules =
        Seq(ExampleModule))
      .create

  test("MyTest#perform feature") {
    val exampleThingy = injector.instance[ExampleThingy]
    ...
  }
}

Caution

The injector is specified as a def the in c.t.inject.IntegrationTestMixin trait. If you only want to start one instance of your injector per test file make sure to override this def with a val.

Http Tests

If you are writing a test that has an HTTP server under test, you can also extend the c.t.finatra.http.HttpTest trait. This trait provides some common utilities for HTTP testing, specifically utilities for constructing a resolverMap flag value for setting on your server under test.

Thrift Tests

As shown above, thrift servers can be tested through a c.t.finatra.thrift.ThriftClient. The Finatra test framework provides an easy way get access to a real Finagle client for making calls to your running server in a test.

In the case here, creating a c.t.finatra.thrift.ThriftClient requires the thrift service type T. This type is expected to be the trait subclass of c.t.scrooge.ThriftService in the form of YourService[+MM[_]].

Additionally, your test can also extend the c.t.finatra.thrift.ThriftTest trait which provides a utility specifically for constructing a resolverMap flag value for setting on your server under test.