Pergunta

i've got a Play Framework 2.1.0 application, and even the simplest unit test will not run due to a system problem i'm struggling to track down. given this route:

POST      /foo/bar     controllers.FooBar.test()

...i've got a simple test to verify that the route exists:

@Test
public void fooBarRouteExists() {
    running(fakeApplication(fakeGlobal()), new Runnable() {
        @Override
        public void run() {
            final Result result = route(fakeRequest(POST, "/foo/bar"));
            assertThat(result).isNotNull();
        }
    });
}

...which when run, produces the following Exception:

 hsl [323]> play test
 [info] Loading project definition from /Users/hsl/Documents/workspace/test_project/project
 [info] Set current project to test_project (in build file:/Users/hsl/Documents/workspace/test_project/)
 [info] Compiling 1 Java source to /Users/hsl/Documents/workspace/test_project/target/scala-2.10/test-classes...
 SLF4J: Class path contains multiple SLF4J bindings.
 SLF4J: Found binding in [file:/Users/hsl/Documents/workspace/test_project/target/scala-2.10/classes/org/slf4j/impl/StaticLoggerBinder.class]
 SLF4J: Found binding in [jar:file:/usr/local/play-2.1.0/repository/local/ch.qos.logback/logback-classic/1.0.7/jars/logback-classic.> jar!/org/slf4j/impl/StaticLoggerBinder.class]
 SLF4J: Found binding in [jar:file:/usr/local/play-2.1.0/repository/cache/org.apache.activemq/activemq-all/jars/activemq-all-5.9.0.> jar!/org/slf4j/impl/StaticLoggerBinder.class]
 SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
 [error] Test controllers.FooBar.test failed: null
 [error]     at org.slf4j.LoggerFactory.bind(slf4j:LoggerFactory.java):128)
 [error]     at org.slf4j.LoggerFactory.performInitialization(slf4j:LoggerFactory.java):107)
 [error]     at org.slf4j.LoggerFactory.getILoggerFactory(slf4j:LoggerFactory.java):295)
 [error]     at org.slf4j.LoggerFactory.getLogger(slf4j:LoggerFactory.java):269)
 [error]     at play.api.Logger$.<init>(Logger.scala:179)
 [error]     at play.api.Logger$.<clinit>(Logger.scala)
 [error]     at play.api.Application$class.$init$(Application.scala:266)
 [error]     at play.api.test.FakeApplication.<init>(Fakes.scala:187)
 [error]     at play.test.FakeApplication.<init>(FakeApplication.java:28)
 [error]     at play.test.Helpers.fakeApplication(Helpers.java:97)
 [error]     at controllers.FooBar.test(FooBar.java:20)
 [error]     ...
 [error] Caused by: java.lang.UnsupportedOperationException: This code should have never made it into slf4j-api.jar
 [error]     at org.slf4j.impl.StaticLoggerBinder.<init>(impl:StaticLoggerBinder.java):63)
 [error]     at org.slf4j.impl.StaticLoggerBinder.<clinit>(impl:StaticLoggerBinder.java):44)
 [error]     ... 42 more
 [error] Failed: : Total 1, Failed 1, Errors 0, Passed 0, Skipped 0
 [error] Failed tests:
 [error]    controllers.FooBar
 java.lang.RuntimeException: Tests unsuccessful
    at scala.sys.package$.error(package.scala:27)
    at scala.Predef$.error(Predef.scala:123)
    at sbt.Tests$.showResults(Tests.scala:192)
    at sbt.Defaults$$anonfun$testTasks$6.apply(Defaults.scala:296)
    at sbt.Defaults$$anonfun$testTasks$6.apply(Defaults.scala:294)
    at sbt.Scoped$$anonfun$hf4$1.apply(Structure.scala:580)
    at sbt.Scoped$$anonfun$hf4$1.apply(Structure.scala:580)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:49)
    at sbt.coped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311)
    at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:41)
    at sbt.std.Transform$$anon$5.work(System.scala:71)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:232)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:232)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:238)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)
 [error] (test:test) Tests unsuccessful> 

can someone help me figure out what the problem is?

Foi útil?

Solução

The key error message is at the top:

 SLF4J: Class path contains multiple SLF4J bindings.
 SLF4J: Found binding in [file:/Users/hsl/Documents/workspace/test_project/target/scala-2.10/classes/org/slf4j/impl/StaticLoggerBinder.class]
 SLF4J: Found binding in [jar:file:/usr/local/play-2.1.0/repository/local/ch.qos.logback/logback-classic/1.0.7/jars/logback-classic.> jar!/org/slf4j/impl/StaticLoggerBinder.class]
 SLF4J: Found binding in [jar:file:/usr/local/play-2.1.0/repository/cache/org.apache.activemq/activemq-all/jars/activemq-all-5.9.0.> jar!/org/slf4j/impl/StaticLoggerBinder.class]
 SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

That's interesting, it looks like you have put (some of) the source code for sl4j in your test project, so that Play is compiling it. This causes the problem you are experiencing.

Remove the source code for slf4j from your test project, and it should work.

By the way, you can still have the source accessible for reference - e.g. if you are using Eclipse you can attach corresponding source to a jar in your project. play "eclipse with-sources" will do that automatically, for dependencies that have correctly published their source jars to their Maven or Ivy repository.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top