简体   繁体   中英

Is it possible to make scalatest to discover within package object?

I have several test facets sharing multiple test classes, so I aggregate them into a trait to be mixin into package objects, expecting that those test classes will be discovered under the package:

(In trait)

trait AbstractPackageTests {

  val name: String

  class Suite1 extends FunSpec {

    describe(name) {

      it("test 1") {}

      it("test 2") {}
    }
  }

  class Suite2 extends FunSpec {
    describe(name) {

      it("test 3") {}

      it("test 4") {}
    }
  }
}

(In package 1)

package com.spike.scalatest_spike

package object facet1 extends FunSpec with AbstractPackageTests {
  override val name: String = "facet 1"

  class Suite3 extends FunSpec {
    describe(name) {

      it("test 5") {}

    }
  }
}

(In package 2)

package com.spike.scalatest_spike

package object facet2 extends AbstractPackageTests {
  override val name: String = "facet 2"
}

Unfortunately it appears that none of these classes (Suite1, Suite2, Sutie3) can be discovered when I invoke scalatest to run all the test under com.spike.scalatest_spike , the classes seems to be ignored in class discovery.

What changes should I make on my project or/and scalatest sourcecode to make it working?

If you're using SBT to invoke the testing then ensure sources are in src/test/scala or src/test/java as documented: https://www.scala-sbt.org/1.x/docs/Testing.html

If you're using a jar with the java or scala commands, it's possible your test classes are missing from the jar. The former method may be easier since it doesn't require a jar to have all your test classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM