2015-03-03 58 views
2

中播放Logger V2.3測試不起作用:如何在Play framework v2.3測試中啓用記錄器?

"Test example" should { 
    "Test 1" in { 
    import play.api.Logger 

    Logger.debug("hello world") // doesn't work, no output on screen 
    } 
} 

但如果我WithApplication包裝測試,它的工作原理:

"Test example" should { 
    "Test 1" in new WithApplication { 
    import play.api.Logger 

    Logger.debug("hello world") 
    } 
} 

但它給管理費,如果我必須包裝使用WithApplication進行每項測試只是爲了讓Logger工作。

因此,任何人都知道如何讓記錄器在沒有WithApplication的情況下工作?

+0

你從'application.conf啓用記錄器的例子'? – silentprogrammer 2015-03-03 11:36:13

+0

你在使用['scalatestplus'](http://www.scalatest.org/plus/play)嗎?如果是的話,你可以使用['OneServerPerSuite'](http://doc.scalatest.org/plus-play/1.0.0/index.html#org.scalatestplus.play.OneServerPerSuite)或'OneServerPerTest'特性,假應用程序給你的上下文。如果你已經在使用['scalatest'](http://www.scalatest.org),這是一個下降的選擇。 – 2015-03-03 11:52:09

+0

@singhakash:是的,如果沒有,使用'WithApplication'的第二次測試將不會成功。 @Nader:我使用使用specs2的內置遊戲測試庫。 – null 2015-03-03 16:36:11

回答

0

如果您正在使用scalatestplus應覆蓋FakeApplication額外的配置記錄程序,在這裏你有工作

import org.scalatest._ 
import play.api.test._ 
import play.api.test.Helpers._ 
import org.scalatestplus.play._ 

import play.api.Logger 

class TestExampleLogger extends PlaySpec with OneAppPerSuite { 

    // Override app if you need a FakeApplication with other than 
    // default parameters. 
    implicit override lazy val app: FakeApplication = FakeApplication(additionalConfiguration = Map(
    "logger.application" -> "DEBUG" 
)) 

    "Test example" should { 
    "Test 1" in { 
     import play.api.Logger 

     Logger.debug("hello world") // doesn't work, no output on screen 
    } 
    } 

} 

希望它可以幫助

+0

不起作用... – Ixx 2015-12-03 18:26:52

相關問題