specs2

Writing a test case for file uploads in Play 2.1 and Scala

隐身守侯 提交于 2019-11-30 15:07:46
问题 I found the following question/answer: Test MultipartFormData in Play 2.0 FakeRequest But it seems things have changed in Play 2.1. I've tried adapting the example like so: "Application" should { "Upload Photo" in { running(FakeApplication()) { val data = new MultipartFormData(Map(), List( FilePart("qqfile", "message", Some("Content-Type: multipart/form-data"), TemporaryFile(getClass().getResource("/test/photos/DSC03024.JPG").getFile())) ), List()) val Some(result) = routeAndCall(FakeRequest

How can I roll back an integration test with Slick 3 + Specs2?

岁酱吖の 提交于 2019-11-30 14:01:49
问题 I want to write some integration tests for a service that runs slick and then clean a postgresql database up afterward up by rolling back a transaction, but I don't see a way to do it. I understand that I can test DBIO objects which have been composed together and roll them back, but it doesn't look like it's possible if I want to test at a higher level of abstraction. In pseudocode, I want to do this: StartDbTransaction() // setup DoSomethingInDB() AssertSomething() RollBackDbTransaction() /

Writing a test case for file uploads in Play 2.1 and Scala

允我心安 提交于 2019-11-30 12:42:01
I found the following question/answer: Test MultipartFormData in Play 2.0 FakeRequest But it seems things have changed in Play 2.1. I've tried adapting the example like so: "Application" should { "Upload Photo" in { running(FakeApplication()) { val data = new MultipartFormData(Map(), List( FilePart("qqfile", "message", Some("Content-Type: multipart/form-data"), TemporaryFile(getClass().getResource("/test/photos/DSC03024.JPG").getFile())) ), List()) val Some(result) = routeAndCall(FakeRequest(POST, "/admin/photo/upload", FakeHeaders(), data)) status(result) must equalTo(CREATED) headers(result)

running multiple tests within the same FakeApplication() in play 2.0 scala

橙三吉。 提交于 2019-11-30 11:35:50
问题 I am trying to learn the unit tests in Play scala, but I am running into some issues. I am trying to run several tests on my models layer like this: "User Model" should { "be created and retrieved by username" in { running(FakeApplication()) { val newUser = User(username = "weezybizzle",password = "password") User.save(newUser) User.findOneByUsername("weezybizzle") must beSome } } "another test" in { running(FakeApplication()) { // more tests involving adding and removing users } } } However

How can I roll back an integration test with Slick 3 + Specs2?

送分小仙女□ 提交于 2019-11-30 09:06:13
I want to write some integration tests for a service that runs slick and then clean a postgresql database up afterward up by rolling back a transaction, but I don't see a way to do it. I understand that I can test DBIO objects which have been composed together and roll them back, but it doesn't look like it's possible if I want to test at a higher level of abstraction. In pseudocode, I want to do this: StartDbTransaction() // setup DoSomethingInDB() AssertSomething() RollBackDbTransaction() // teardown For example, if I have this (simplified from the play-silhouette-slick-seed ): class

Parallel execution of tests

≯℡__Kan透↙ 提交于 2019-11-30 00:58:00
问题 I've noticed that SBT is running my specs2 tests in parallel. This seems good, except one of my tests involves reading and writing from a file and hence fails unpredictably, e.g. see below. Are there any better options than setting all tests to run in serial, using separate file names and tear-downs for each test? class WriteAndReadSpec extends Specification{ val file = new File("testFiles/tmp.txt") "WriteAndRead" should { "work once" in { new FileWriter(file, false).append("Foo").close

running multiple tests within the same FakeApplication() in play 2.0 scala

时间秒杀一切 提交于 2019-11-30 00:31:28
I am trying to learn the unit tests in Play scala, but I am running into some issues. I am trying to run several tests on my models layer like this: "User Model" should { "be created and retrieved by username" in { running(FakeApplication()) { val newUser = User(username = "weezybizzle",password = "password") User.save(newUser) User.findOneByUsername("weezybizzle") must beSome } } "another test" in { running(FakeApplication()) { // more tests involving adding and removing users } } } However when doing things this way, I fail to connect to the database on the second unit test, saying that the

Specs2: how to test a class with more than one injected dependency?

时光怂恿深爱的人放手 提交于 2019-11-28 12:18:09
Play 2.4 app, using dependency injection for service classes. I found that Specs2 chokes when a service class being tested has more than one injected dependency. It fails with " Can't find a constructor for class ... " $ test-only services.ReportServiceSpec [error] Can't find a constructor for class services.ReportService [error] Error: Total 1, Failed 0, Errors 1, Passed 0 [error] Error during tests: [error] services.ReportServiceSpec [error] (test:testOnly) sbt.TestsFailedException: Tests unsuccessful [error] Total time: 2 s, completed Dec 8, 2015 5:24:34 PM Production code , stripped to

How to force Logger.debug output in Play! framework specs2 tests?

别来无恙 提交于 2019-11-28 03:59:14
By default all Logger output, visible when an application is running, is mute when the application is tested. How to force the debugs, infos etc. to be shown in the specs2 reports? First off, you may like some background why logging is disabled in test mode. This was Guillame Bort's answer to a question in the play forum (see this thread ): The logger is disabled in test mode for now because it was causing an huge PermGen space leak when running tests. But we are working to run tests in a forked JVM so we will enable it again soon. As a workaround, I created my own logger like this (Scala code

Specs2: how to test a class with more than one injected dependency?

て烟熏妆下的殇ゞ 提交于 2019-11-27 06:09:22
问题 Play 2.4 app, using dependency injection for service classes. I found that Specs2 chokes when a service class being tested has more than one injected dependency. It fails with " Can't find a constructor for class ... " $ test-only services.ReportServiceSpec [error] Can't find a constructor for class services.ReportService [error] Error: Total 1, Failed 0, Errors 1, Passed 0 [error] Error during tests: [error] services.ReportServiceSpec [error] (test:testOnly) sbt.TestsFailedException: Tests