Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] OneBrowserPerSuite: How to prevent browser startup when skipping tests using this trait? #100

Open
el-dom opened this issue Jun 30, 2017 · 2 comments

Comments

@el-dom
Copy link

el-dom commented Jun 30, 2017

I'm in a scenario where unittests and fluentlenium integration tests are placed in the same module but need to be run seperately at different stages of deployment in different environments.

A Fluentlenium Spec might look like this

@IntegrationTest
class IntegrationSpec extends WordSpec with MustMatchers  with GuiceOneServerPerSuite with OneBrowserPerSuite {
 override def fakeApplication(): Application = FluentleniumSetup.app
 override def createWebDriver(): WebDriver = FluentleniumSetup.createWebDriver()
...
}

and a unit test like this

@UnitTest
class FooSpec extends WordSpec with MustMatchers with TypeCheckedTripleEquals {
...
}

To be able to seperate the test executions, this configuration in build.sbt was created:

lazy val ITest = config("i").extend(Test)
lazy val UTest = config("u").extend(Test)
testOptions in ITest += Tests.Argument(TestFrameworks.ScalaTest, "-l","foo.bar.UnitTest
testOptions in UTest += Tests.Argument(TestFrameworks.ScalaTest, "-l","foo.bar.IntegrationTest")

This way i can run sbt u:test and all suits annotated with @IntegrationTest will be skipped due to the exclude flag -l.
But still, whenever test execution reaches a Test annotated with IntegrationSpec, a browser gets started and closes immediately without doing anything, because all tests in this Suite get skipped. Since there is no browser installed in the environment where u:test is meant to be executed, this attempt to start a browser breaks test execution. Which is unfortunate because it wouldn't be necessary to start a browser at all. Am i doing something wrong in my attempt to skip the Testsuits?

@el-dom
Copy link
Author

el-dom commented Jul 7, 2017

So right now my last resort was to extend the OneBrowserPerSuite trait, override run, check for excludedTags and just return SucceededStatus if the suite should be skipped due to its annotations.

trait OneBrowserPerSuite extends org.scalatestplus.play.OneBrowserPerSuite { this: TestSuite with ServerProvider =>
  abstract override def run(testName: Option[String], args: Args): Status = {
    val excludedTags = this.getClass.getAnnotations.map(_.annotationType().getName).filter(args.filter.tagsToExclude.contains)
    if (excludedTags.nonEmpty) {
      new CompositeStatus(Set(SucceededStatus))
    } else {
      super.run(testName, args)
    }
  }
}

@marcospereira Would it make sense to do something similar for org.scalatestplus.play.OneBrowserPerSuite? I'm aware tests get skipped even without this hack, and most people wouldn't care about the browser startup, but i think it would make sense to prevent the startup, since it's unnecessary when the suite shall be skipped anyway.

@kwinter
Copy link

kwinter commented Apr 28, 2020

having poked around to trying to decouple from the async tests, I believe the issue is that the current hooks use:

abstract override def run(testName: Option[String], args: Args): Status

which gets executed even if a test is filtered out. A course of action may be to use BeforeAndAfterAll to start/stop (I'll be opening a PR for the non-browser suites with this), and override either:

  • testDataFor
  • runTest

to include the driver instance in the config map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants