0

I am trying to set up integration tests to prepare our database. I am using sbt 1.0.3 and Scala 2.11.11 in Play 2.6.12.

I added this section in build.sbt:

lazy val fnHelper = taskKey[Unit]("FnTest Helpers")

testOptions in IntegrationTest += Tests.Setup(
  () => {
     println("########################### Prepare Functional Tests #####################")
     fullRunTask(fnHelper, IntegrationTest, "helper.FTTestHelper")
    println("#################################### Finished ")

  });

testOptions in IntegrationTest += Tests.Cleanup( () => println("clean up") )

Below is the task class,

 object FTTestHelper {

  val logger: Logger = Logger(this.getClass())

  def setUpDatabase(): Unit = {
     println("################################Setup metadata database###########################")
      val process = Runtime.getRuntime.exec("main/functionalTest/updateFnDatabaseMetadata.sh")
      if ( process.exitValue() != 0) {
        throw new RuntimeException("fail to update metadata")
      }
  }

  def main(args: Array[String]):Unit = {
    println("############execute FT TestHelper #############")
    setUpDatabase()
  }
}

When I ran "sbt it:test", console shows:

[warn] javaOptions will be ignored, fork is set to false
########################### Prepare Functional Tests #####################
#################################### Finished 

But the FTTestHelper was not executed, even I moved the "fullRunTask(fnHelper, IntegrationTest, "helper.FTTestHelper")" out of Tests.Setup. Did I miss anything here? Thanks

shaohui
  • 71
  • 1
  • 7
  • Could you clarify why are you using `fullRunTask`? I don't think it's supposed to _run a task_, so it's not what you want. – laughedelic Mar 29 '18 at 23:14
  • Probably you could do it with a simple task dependency? https://stackoverflow.com/q/8554992/736957 – laughedelic Mar 29 '18 at 23:17
  • @laughedelic Before my integration tests are executed, I'd like to prepare my test database. Do you have any recommendation? I will take a look at the task dependency. I am using the Tests.setup to prepare my database. I found I could not call helper.FTTestHelper.setUpDatabase() directly either, it can't be found during test. Thanks a lot. – shaohui Mar 29 '18 at 23:30
  • Then how about this: https://stackoverflow.com/q/21656812/736957 ? – laughedelic Mar 30 '18 at 03:31

0 Answers0