Pregunta

I am using Java in Play framework and I have some tests (functional tests) that are passed when I run them through my IDE (IntelliJ) but failed when I run the tests through console.

My problems is that the stack traces that are shown in the test logs are only 2 lines and I need the complete stack trace to see what is going on in there, I have tried any combination of settings mentioned here: spec2 settings both through putting them in build.sbt or providing them in the command line. It seems that there is no effect! Here is my build.sbt:


version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  filters
)     

logBuffered in Test := false

testOptions += Tests.Argument(TestFrameworks.JUnit, "-v")

testOptions += Tests.Argument("fullStackTrace","true")

traceLevel := 50

Can someone help me please? I am using Typesafe activator (play 2.2.2). Thanks

¿Fue útil?

Solución

In Play 2.3.2 this can be acheieved using the -a option in build.sbt:

testOptions += Tests.Argument(TestFrameworks.JUnit, "-a")

I use:

testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-q", "-a")

as this provides test started/finished messages (-v) and suppresses logging for passed tests (-q).


All of the available options can be found in the SBT JUnit Interface:

  • -v Log "test run started" / "test started" / "test run finished" events on log level "info" instead of "debug".
  • -q Suppress stdout for successful tests. Stderr is printed to the console normally. Stdout is written to a buffer and discarded when a test succeeds. If it fails, the buffer is dumped to the console. Since stdio redirection in Java is a bad kludge (System.setOut() changes the static final field System.out through native code) this may not work for all scenarios. Scala has its own console with a sane redirection feature. If Scala is detected on the class path, junit-interface tries to reroute scala.Console's stdout, too.
  • -n Do not use ANSI colors in the output even if sbt reports that they are supported.
  • -s Try to decode Scala names in stack traces and test names. Fall back silently to non-decoded names if no matching Scala library is on the class path.
  • -a Show stack traces and exception class name for AssertionErrors (thrown by all assert* methods in JUnit). Without this option, failed assertions do not print a stack trace or the "java.lang.AssertionError: " prefix.
  • -c Do not print the exception class name prefix for any messages. With this option, only the result of getMessage() plus a stack trace is shown.
  • +v Turn off -v. Takes precedence over -v.
  • +q Turn off -q. Takes precedence over -q.
  • +n Turn off -n. Takes precedence over -n.
  • +s Turn off -s. Takes precedence over -s.
  • +a Turn off -a. Takes precedence over -a.
  • +c Turn off -c. Takes precedence over -c.
  • --ignore-runners=<COMMA-SEPARATED-STRINGS> Ignore tests with a @RunWith annotation if the Runner class name is contained in this list. The default value is org.junit.runners.Suite.
  • --tests=<REGEXPS> Run only the tests whose names match one of the specified regular expressions (in a comma-separated list). Non-matched tests are ignored. Only individual test case names are matched, not test classes. Example: For test MyClassTest.testBasic() only "testBasic" is matched. Use sbt's test-only command instead to match test classes.
  • -Dkey=value Temporarily set a system property for the duration of the test run. The property is restored to its previous value after the test has ended. Note that system properties are global to the entire JVM and they can be modified in a non-transactional way, so you should run tests serially and not perform any other tasks in parallel which depend on the modified property.
  • --run-listener=<CLASS_NAME> A (user defined) class which extends org.junit.runner.notification.RunListener. An instance of this class is created and added to the JUnit Runner, so that it will receive the run events. For more information, see RunListener. Note: this uses the test-classloader, so the class needs to be defined in src/test or src/main or included as a test or compile dependency
  • --include-categories=<CLASSES> A comma separated list of category class names that should be included. Only tests with one or more of these categories will be run.
  • --exclude-categories=<CLASSES> A comma separated list of category class names that should be excluded. No tests that match one or more of these categories will be run.

Otros consejos

Play 2.2.3 was just released. Includes a fix for bug 2535, which I think might be the issue you're seeing.

https://groups.google.com/forum/#!topic/play-framework/KP1_DbhcxlU

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top