Re: Starting and stopping Jetty in IntegrationTest

256 views
Skip to first unread message

James Earl Douglas

unread,
Jun 27, 2012, 10:06:56 PM6/27/12
to simple-b...@googlegroups.com
Not an sbt-specific answer, but I generally test by having my test cases launch Jetty directly.  It's not exactly what you're asking for, but it might be a helpful stopgap: https://github.com/JamesEarlDouglas/jetty-testing

On Wednesday, June 27, 2012 11:16:55 AM UTC-7, Reggie wrote:
Can anyone give me a clue on this? This seems to indicate that the problem is easy and I'm overlooking something, or that the problem is tough. I'm willing to  contribute to make this happen if I can be pointed in the right direction.

-Reggie

On Monday, June 18, 2012 1:43:05 PM UTC-7, Reggie wrote:
I'm using SBT for the first time and am trying to recreate what I was able to do using maven as far as running integration tests. In maven I am able to start the jetty service in the pre-integration-test stage and stop jetty in the post-integration-test stage. How can I do the equivalent in SBT? The best that I saw was to add .configs(IntegrationTest) to my Project and add a .settings on test in IntegrationTest that says that it depends on PluginKeys.start in WebPlugin.Container.Configuration. That seems to do the start, but how do I do the stop? here is my build file (dependencies are in another file).

import sbt._
import com.github.siasia._
import WebPlugin._
import PluginKeys._
import Keys._

object Build extends sbt.Build {
  import Dependencies._

  lazy val myProject = Project("mba-core", file("."))
    .configs( IntegrationTest )
    .settings( Defaults.itSettings : _*)
    .settings(WebPlugin.webSettings: _*)
    .settings(port in config("container") := 8080)
    .settings(
      organization  := "com.marchex",
      version       := "1.0",
      scalaVersion  := "2.9.1",
      scalacOptions := Seq("-deprecation", "-encoding", "utf8"),
      resolvers     ++= Dependencies.resolutionRepos,
      libraryDependencies ++=
        compile(akkaActor, sprayServer, jaxbImpl, jaxbApi, jaxbXjc, liftJson, sprayJson, jerseyClnt, jerseyJson, JxonMapper, scalazCore) ++
        testTime(scalaTest, specs2, junit) ++
        itTime(scalaTest, specs2, junit, jerseyClnt) ++
        container(jettyWebApp, akkaSlf4j, slf4j, logback)
    )
    .settings(test in IntegrationTest <<= (test in IntegrationTest).dependsOn(com.github.siasia.PluginKeys.start in com.github.siasia.WebPlugin.container.Configuration))

}

Thanks

-Reggie

chris

unread,
Jun 29, 2012, 4:03:31 AM6/29/12
to simple-b...@googlegroups.com
Have you tried the following?

test in IntegrationTest <<= (com.github.siasia.PluginKeys.stop in com.github.siasia.WebPlugin.container.Configuration).dependsOn(test in IntegrationTest).dependsOn(
  com.github.siasia.PluginKeys.start in com.github.siasia.WebPlugin.container.Configuration)

Mark Harrah

unread,
Jun 29, 2012, 7:17:54 PM6/29/12
to simple-b...@googlegroups.com
dependsOn is not intended for sequencing. See this thread:

https://groups.google.com/d/topic/simple-build-tool/Ki8orLenppk/discussion

and specifically the last paragraph in this post:

https://groups.google.com/d/msg/simple-build-tool/Ki8orLenppk/cgcGDMPgFh8J

The suggestion to have the test case launch Jetty directly is the best one, in my opinion. Test frameworks usually have good support for handling this kind of setup and shutdown.

Should you want to start and stop in sbt, see the Setup and Cleanup section of:

https://github.com/harrah/xsbt/wiki/Testing

-Mark

On Fri, 29 Jun 2012 13:30:19 -0700 (PDT)
Reggie <reggie...@gmail.com> wrote:

> That worked nicely. Thanks. I wonder is there an alternative in the DSL
> that makes this sequence look more intuitive.
>
> Thanks again.
>
> -Reggie
> --
> You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/simple-build-tool/-/H4fch3Z460AJ.
> To post to this group, send email to simple-b...@googlegroups.com.
> To unsubscribe from this group, send email to simple-build-t...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/simple-build-tool?hl=en.
>

Reply all
Reply to author
Forward
0 new messages