How to run specifications sequentially

后端 未结 3 1868
温柔的废话
温柔的废话 2021-02-06 23:20

I want to create few specifications that interoperate with database.

class DocumentSpec extends mutable.Specification with BeforeAfterExample {
  sequential

  d         


        
相关标签:
3条回答
  • 2021-02-07 00:00

    I suppose you are using SBT? If so, check the documentation: http://www.scala-sbt.org/release/docs/Detailed-Topics/Parallel-Execution

    The relevant SBT setting is parallelExecution. Add this to your project definition:

    parallelExecution in Test := false
    
    0 讨论(0)
  • 2021-02-07 00:10

    If you want to run single Specification in specs2 sequentially just add sequential method call at the beginning of your Specification. For example:

    class MyTest extends Specification {
      // Set sequential execution
      sequential
    
      // This tests will be executed sequentially
      "my test" should {
        "add numbers" in {
          (1 + 1) should be equalTo 2
        }
    
        "multiply numbers" in {
          (2 * 2) should be equalTo 4
        }
      }
    } 
    

    UPDATE: As @jsears correctly mentioned in the comments, this will make tests to run sequentially in a single spec! Other specs may still run in parallel.

    0 讨论(0)
  • 2021-02-07 00:27

    Meanwhile there is a better solution (http://www.scala-sbt.org/release/docs/Parallel-Execution.html):

    sbt 0.12.0 introduces a general infrastructure for restricting task concurrency beyond the usual ordering declarations.

    This configuration will run all tests sequential, also if they are in subprojects:

    concurrentRestrictions in Global := Seq(
      Tags.limit(Tags.CPU, 2),
      Tags.limit(Tags.Network, 10),
      Tags.limit(Tags.Test, 1),
      Tags.limitAll( 15 )
    )
    

    I haven't tested if this can be overridden by each sub-project, so the sub-project can run its tests in parallel.

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