How do you share classes between test configurations using SBT

后端 未结 4 1825
野的像风
野的像风 2021-01-01 18:05

I have followed the instructions on SBT\'s documentation for setting up test configurations. I have three test configurations Test, IntegrationTest, and AcceptanceTest. So m

相关标签:
4条回答
  • 2021-01-01 18:20

    A configuration can extend another configuration to use that configuration's dependencies and classes. For example, the custom test configuration section shows this definition for the custom configuration:

    lazy val FunTest = config("fun") extend(Test)
    

    The extend part means that the compiled normal test sources will be on the classpath for fun sources. In your case, declare the acceptance configuration to extend the it configuration:

    lazy val AcceptanceTest = config("acceptance") extend(IntegrationTest)
    
    0 讨论(0)
  • 2021-01-01 18:25

    SBT uses the Maven default directory layout.

    It will recognize folders unders src/test/scala to compile along with src/main/scala.

    So, if you move the other folders under src/test/scala SBT will compile them and you can share code between them. e.g.:

    └── scala
        ├── acceptance
        │   └── scala
        │       └── Acceptance.scala
        ├── it
        │   └── scala
        │       └── IT.scala
        └── Test.scala
    

    Running sbt test will compile all three files in the directory. So, with this Acceptance refer to and can create a new IT class for example.

    0 讨论(0)
  • 2021-01-01 18:26

    In case you want to stick with predefined configurations instead of defining new ones, and since both Test and IntegrationTest extend Runtime (one would expect IntegrationTest to extend Test…), you could use the following:

    dependencyClasspath in IntegrationTest := (dependencyClasspath in IntegrationTest).value ++ (exportedProducts in Test).value
    

    This should put all the classes you define in Test on the IntegrationTest classpth.

    ##EDIT:

    I was just became aware to amuch better solution thanks to @mjhoy:

    lazy val DeepIntegrationTest = IntegrationTest.extend(Test)
    
    0 讨论(0)
  • 2021-01-01 18:38

    An approach is documented here: http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing#additional-test-configurations-with-shared-sources

    0 讨论(0)
提交回复
热议问题