twitter / finatra

Fast, testable, Scala services built on TwitterServer and Finagle
https://twitter.github.io/finatra/
Apache License 2.0
2.27k stars 406 forks source link

object FeatureTest is not a member of package com.twitter.inject.server #519

Closed MeerKatDev closed 4 years ago

MeerKatDev commented 4 years ago

As in the title, after including the sbt package finatra-http, and trying to run this example: https://github.com/twitter/finatra/blob/a79f56347acd2194e415975ab125e2509c8e91e5/examples/http-server/src/test/scala/com/twitter/hello/HelloWorldFeatureTest.scala this error appears, along with "Symbol 'type com.twitter.inject.server.EmbeddedTwitterServer' is missing from the classpath." and "not found: type HelloWorldServer". Also, in general the documentation is broken.

jyanJing commented 4 years ago

Thanks @MeerKatDev. the package finatra-http should have the test dependencies on inject-server at a quick glance to our finatra-http sbt build setting. It might be related to how you set up your sbt file. Would you mind providing more information specific to the way you set up your sbt, especially how you include the finatra-http package? Which command you used to run the test? Also, what is the broken documentation you were referring to? We would like to fix it, thank you!

MeerKatDev commented 4 years ago

I actually took a look at the artefact for com.twitter.inject.server, and FeatureTest class is simply not in there. the command I used is "sbt test". You are not specifying anything in the docs, so it should just work after inputs. About the broken doc - many links simply give 404. It's difficult to find information when something doesn't work.

jyanJing commented 4 years ago

Hi @MeerKatDev , I have checked all links in our finatra user guide and no one returns a 404, all pages loaded with content. Would appreciate if you could paste the link to any broken docs, thank you!

jyanJing commented 4 years ago

Per the artifact dependencies, both com/twitter/inject/server/FeatureTest and com/twitter/inject/server/EmbeddedTwitterServer are published in injectServer, which is a dependency of finatra-http, which is a dependency of examples/http-server, so you should be able to run the test (which is under examples/http-server) without issues, it looks like to me all the dependencies are taken care of by finatra. So the issue you are seeing might be related to how you set up your sbt file, sometimes working with sbt dependencies can be tricky. So it would be great to know how you set up the sbt file in order for us to help :-)

MeerKatDev commented 4 years ago

well, I can import and use classes from finatra.http, so it should be able to find its dependencies, no?

MeerKatDev commented 4 years ago

if it's so important:

lazy val finatra = "com.twitter" %% "finatra-http" % "19.12.0"

lazy val api = (project in file("api")) .settings( libraryDependencies += finatra, libraryDependencies += finatra % "test" classifier "tests" )

is there something weird here?

jyanJing commented 4 years ago

I'm having troubles understanding what you are trying to do here. Note that finatra-http doesn't include examples/http-server which loads the HelloWorldFeatureTest.scala you are trying to run. If you want to run the test, please include the project examples/http-server.

I also did a test in local and the HelloWorldFeatureTest.scala passes without any errors. There's no failures in our open source sbt build either. So it is more depending on setting up your sbt based on what you want to achieve.

MeerKatDev commented 4 years ago

Where is this mentioned in the docs, that you have to include examples/http-server in the build? I thought it's just part of the standard test API.

MeerKatDev commented 4 years ago

When you go into the testing section: https://twitter.github.io/finatra/user-guide/testing/index.html and to the feature test section (I think someone would want to just test code at that point), and it's written that there are examples (See an example feature test here.).

At this point I don't want to search the whole repository for the build.sbt and search which dependencies correspond to what. Even in the READMEs nothing is written about dependencies to include.

It's just easier to use Netty and ScalaTest at this point.

MeerKatDev commented 4 years ago

And about your dependencies: I could resolve some issues with the classpath only by including manually all of these libraries:

lazy val twitterServer = "com.twitter"      %% "inject-server"  % "19.12.0"
  lazy val twitterServerApp = "com.twitter"   %% "inject-app"     % "19.12.0",
  lazy val twitterServerCore = "com.twitter"  %% "inject-core"    % "19.12.0"
  lazy val twitterServerMods = "com.twitter"  %% "inject-modules" % "19.12.0"

    libraryDependencies += twitterServer % "test" classifier "tests",
    libraryDependencies += twitterServerApp % "test" classifier "tests",
    libraryDependencies += twitterServerCore % "test" classifier "tests",
    libraryDependencies += twitterServerMods % "test" classifier "tests",
jyanJing commented 4 years ago

Thanks @MeerKatDev ,

As I read through the doc, it mentioned that users can see the examples, meaning you can follow the examples to write your own tests, in that way, you don't need to include the example package. But if you were trying to run that test, as in your problem description, you would need to include that so your build file can know where to look for all the dependencies you need to run that particular test. We will try to add more descriptions regarding running the tests in the example.

Another thing you could try is, instead of including all libraries manually, maybe use something like "test->test" when you define the libraryDependencies, this will make the test in your project depend on the test config in finatra. If you don't specify that, it will make your test target depend on the compile config in finatra.

cacoco commented 4 years ago

@MeerKatDev if you take a look at the very first page of the documentation, it tries to explain basics of the framework, including information about test dependencies: http://twitter.github.io/finatra/#test-dependencies. We'll take it as an action item to add a linkback to this documentation specifically from the testing section. Thanks!