2012-03-20 40 views
13

tôi chạy scalatest tôi từ SBT, và đầu ra bị lẫn lộn - in scalatest tất cả các quá trình chạy thử, và ý kiến ​​đối với họ, và đâu đó ở giữa nó in số liệu thống kê:Tại sao scalatest kết hợp đầu ra?

> test 
[info] Compiling 1 Scala source to /home/platon/Tor/scala-dojo-02/target/scala-2.9.1/classes... 
[info] FunsWithListsTests: 
[info] - should return list of labels 
[info] - should return the average rating of games belonging to Zenga 
[info] - should return the total ratings of all games 
[info] - should return the total ratings of EA games *** FAILED *** 
[info] 0 did not equal 170 (FunsWithListsTests.scala:35) 
[error] Failed: : Total 8, Failed 5, Errors 0, Passed 3, Skipped 0 
[info] - should increase all games rating by 10 *** FAILED *** 
[error] Failed tests: 
[error]  dojo.FunsWithListsTests 
[info] List() did not equal List(Game(Activision,40), Game(Zenga,70), Game(Zenga,20), Game(EA,70), Game(EA,120)) (FunsWithListsTests.scala:40) 
[info] - should decrease all Zenga games rating by 10 *** FAILED *** 
[info] List() did not equal List(Game(Activision,30), Game(Zenga,50), Game(Zenga,0), Game(EA,60), Game(EA,110)) (FunsWithListsTests.scala:45) 
[info] - should create function to find Activision games *** FAILED *** 
[info] List(Game(Activision,30), Game(Zenga,60), Game(Zenga,10), Game(EA,60), Game(EA,110)) did not equal List(Game(Activision,30)) (FunsWithListsTests.scala:50) 
[info] - should return a List of tuples consisting of game label and game *** FAILED *** 
[info] List() did not equal List((ACTIVISION,Game(Activision,30)), (ZENGA,Game(Zenga,60)), (ZENGA,Game(Zenga,10)), (EA,Game(EA,60)), (EA,Game(EA,110))) (FunsWithListsTests.scala:56) 
[error] {file:/home/platon/Tor/scala-dojo-02/}default-940f03/test:test: Tests unsuccessful 
[error] Total time: 1 s, completed Mar 20, 2012 9:27:13 AM 

Dường như nếu tôi sẽ tích lũy một số lượng lớn các thử nghiệm, tìm kiếm những số liệu thống kê đó và kiểm tra không thành công sẽ trở thành một cơn đau.

Có cách nào để sửa lỗi này không?

+0

Bạn có thể cung cấp ví dụ tối thiểu để tái tạo điều này không? Tôi đã không thể sản xuất một đầu ra như thế này. – drexin

+0

@drexin - https://github.com/Rogach/scala_dojo – Rogach

+0

@drexin - không chính xác tối thiểu, nhưng đây là nơi tôi phát hiện ra nó. – Rogach

Trả lời

6

Dường như với tôi lý do cho điều đó là SBT theo mặc định thực hiện các kiểm tra song song, giống như cách mà maven-surefire-plugin thực hiện.

Vì nó được giải thích trong ScalaTest wiki, điều này có thể được giải quyết bằng cách:

Disable Thực hiện song song các xét nghiệm Theo mặc định, SBT chạy tất cả các nhiệm vụ song song. Bởi vì mỗi bài kiểm tra được ánh xạ tới một nhiệm vụ, các bài kiểm tra cũng được chạy song song theo mặc định. Để vô hiệu hóa việc thực hiện thử nghiệm song song:

song songKiểm tra trong thử nghiệm: = false

1

Có cùng vấn đề và giải quyết bằng cách lưu nhật ký vào các tệp riêng biệt. Không lý tưởng, nhưng tốt cho CI, đặc biệt là trong trường hợp thử nghiệm tích hợp lâu dài. Làm thế nào tôi đã làm nó:

  1. Tạo một thư mục đặc biệt đối với các bản ghi (ví dụ, vào cuối build.sbt):

    lazy val logDirectory = taskKey[File]("A directory for logs") 
    logDirectory := { 
        val r = target.value/"logs" 
        IO.createDirectory(r) 
        r 
    } 
    
  2. [Tùy chọn] Chỉ định một tập tin cho một thông tin tóm tắt trong một dự án:

    testOptions in test += Tests.Argument(
        TestFrameworks.ScalaTest, "-fW", (logDirectory.value/"summary.log").toString 
    ) 
    

    W vô hiệu hóa màu sắc

  3. Tạo một nhóm cho mỗi bài kiểm tra. Mỗi nhóm phải chạy một thử nghiệm trong một JVM chia hai với lập luận đặc biệt:

    testGrouping in test := testGrouping.value.flatMap { group => 
        group.tests.map { suite => 
        val fileName = { 
         // foo.bar.baz.TestSuite -> f.b.b.TestSuite 
         val parts = suite.name.split('.') 
         (parts.init.map(_.substring(0, 1)) :+ parts.last).mkString(".") 
        } 
    
        val forkOptions = ForkOptions(
         bootJars = Nil, 
         javaHome = javaHome.value, 
         connectInput = connectInput.value, 
         outputStrategy = outputStrategy.value, 
         runJVMOptions = javaOptions.value ++ Seq(
         "-Dour.logging.appender=FILE", 
         s"-Dour.logging.dir=${logDirectory.value/fileName}" 
        ), 
         workingDirectory = Some(baseDirectory.value), 
         envVars = envVars.value 
        ) 
    
        group.copy(
         name = suite.name, 
         runPolicy = Tests.SubProcess(forkOptions), 
         tests = Seq(suite) 
        ) 
        } 
    } 
    

    Lưu ý, chúng ta có thể nói với logback, nơi chúng tôi lưu các bản ghi của chúng tôi thông qua our.logging.appenderour.logging.dir

  4. Tạo một cấu hình để đăng nhập (kiểm tra/nguồn/logback-test.xml):

    <?xml version="1.0" encoding="UTF-8"?> 
    <configuration> 
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
         <target>System.out</target> 
         <encoder> 
          <pattern>%date{yyyy-MM-dd HH:mm:ss} %-5level [%thread] %logger{26} - %msg%n</pattern> 
         </encoder> 
        </appender> 
    
        <appender name="FILE" class="ch.qos.logback.core.FileAppender"> 
         <file>${our.logging.dir}/test.log</file> 
         <append>false</append> 
         <encoder> 
          <pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{26} - %msg%n</pattern> 
         </encoder> 
        </appender> 
    
        <root level="TRACE"> 
         <appender-ref ref="${our.logging.appender}"/> 
        </root> 
    </configuration> 
    

Đó là tất cả.

Các vấn đề liên quan