5
我試圖爲我的應用程序運行一些測試。 應該可以在全新的內存數據庫中運行測試,但我不會讓它工作。運行測試在內存數據庫播放框架
我的測試看起來像現在這樣:
"Server" should {
"persist data for personal user properly" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
//Create personal users
val add1 = route(FakeRequest(POST, "/rest/personaluser").withFormUrlEncodedBody("name" -> "user1" , "email" -> "[email protected]", "password" -> "test123", "gender" -> "male", "birthdate" -> "Oct 1, 2013", "nationality" -> "Sweden")).get
val add2 = route(FakeRequest(POST, "/rest/personaluser").withFormUrlEncodedBody("name" -> "user2" , "email" -> "[email protected]", "password" -> "test123", "gender" -> "male", "birthdate" -> "Oct 1, 2013","nationality" -> "Sweden")).get
status(add1) must equalTo(OK)
status(add2) must equalTo(OK)
//Count users
personalUserRepository.getAllPersonalUsers().length must beEqualTo(2)
//Verify users exist
personalUserRepository.checkIfPersonalUserExists("[email protected]") must beTrue
personalUserRepository.checkIfPersonalUserExists("[email protected]") must beTrue
//Verify user don't exist
personalUserRepository.checkIfPersonalUserExists("[email protected]") must beFalse
//Find user by email
val findUser = route(FakeRequest(GET, "/rest/personaluserbyemail/[email protected]")).get
status(findUser) must equalTo(OK)
contentAsString(findUser) must /("name" -> "user1")
contentAsString(findUser) must /("email" -> "[email protected]")
contentAsString(findUser) must /("gender" -> "male")
contentAsString(findUser) must /("nationality" -> "Sweden")
contentAsString(findUser) must /("facebookID" -> "0")
}
}
}
當我運行此我得到的錯誤InconsistentDatabase: Database 'default' is in inconsistent state!
。 這是因爲標準inMemoryDB可能不支持我用於默認數據庫的MySQL?
不過,我試圖添加memoryDB這樣,而不是:
這裏定義它
def memoryDB = Map("db.default.url" -> "jdbc:h2:mem:playdb;MODE=MYSQL;DB_CLOSE_DELAY=-1;IGNORECASE=TRUE;TRACE_LEVEL_SYSTEM_OUT=1")
而且使用這樣的:
"Server" should {
"persist data for personal user properly" in {
running(FakeApplication(additionalConfiguration = memoryDB)) {
但是,當我不喜歡這樣,它不使用內存分貝,測試在//Count users
失敗,因爲它不等於2,但它7.它使用真正的數據庫,而不是我新的內存分貝我試圖用在這個FakeAp摺疊。
我在做什麼錯,或者我錯過了什麼?
任何可以讓我在正確的軌道上的答案是非常感謝! 謝謝!