如何更改Play Framework 2“测试”设置显示完整的堆栈跟踪? [英] How to change Play Framework 2 "test" settings to show complete stacktraces?

查看:103
本文介绍了如何更改Play Framework 2“测试”设置显示完整的堆栈跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Play框架中使用Java,并且我通过IDE(IntelliJ)运行它时会传递一些测试(功能测试),但是当我通过控制台运行测试时失败。

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.

我的问题是测试日志中显示的堆栈跟踪只有2行,我需要完整的堆栈跟踪才能看到那里发生了什么,我尝试了这里提到的任何设置组合: spec2 settings ,将它们放入 build.sbt 或在命令行中提供它们。似乎没有效果!这是我的 build.sbt

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

有谁可以帮助我吗?我正在使用Typesafe激活器(播放2.2.2)。谢谢

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

推荐答案

播放2.3.2 中,这可以使用来实现 build.sbt中的-a 选项

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

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

我使用:

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

因为这提供了测试开始/完成的消息( -v )并禁止记录通过的测试( -q )。

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

所有可用选项均可在 SBT JUnit界面中找到:

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


  • -v 记录test run started/test started/test run finished 日志级别上的事件信息而不是调试。

  • -q 抑制stdout以获得成功的测试。 Stderr通常会打印到控制台。将Stdout写入缓冲区并在测试成功时丢弃。如果失败,则将缓冲区转储到控制台。由于Java中的stdio重定向是一个糟糕的问题(System.setOut()通过本机代码更改静态最终字段System.out),这可能不适用于所有方案。 Scala拥有自己的控制台,具有理智的重定向功能。如果在类路径上检测到Scala,则junit-interface也会尝试重新路由scala.Console的stdout。

  • -n 不要即使sbt报告它们受支持,也会在输出中使用ANSI颜色。

  • -s 尝试解码堆栈跟踪中的Scala名称测试名称。如果类路径上没有匹配的Scala库,则静默回退到未解码的名称。

  • -a 显示堆栈跟踪和异常AssertionErrors的类名(由JUnit中的所有assert *方法抛出)。如果没有此选项,失败的断言不会打印堆栈跟踪或java.lang.AssertionError:前缀。

  • -c 不要为任何消息打印异常类名称前缀。使用此选项,仅显示getMessage()的结果以及堆栈跟踪。

  • + v 关闭-v。优先于-v。

  • + q 关闭-q。优先于-q。

  • + n 关闭-n。优先于-n。

  • + s 关闭-s。优先于-s。

  • + a 关闭-a。优先于-a。

  • + c 关闭-c。优先于-c。

  • - ignore-runners =< COMMA-SEPARATED-STRINGS> 使用@RunWith忽略测试如果Runner类名称包含在此列表中,则为注释。默认值为org.junit.runners.Suite。

  • - tests =< REGEXPS> 仅运行名称相同的测试匹配其中一个指定的正则表达式(在逗号分隔的列表中)。忽略不匹配的测试。只匹配单个测试用例名称,而不是测试类。示例:对于测试MyClassTest.testBasic(),仅匹配testBasic。使用sbt的test-only命令来匹配测试类。

  • -Dkey = value 在持续时间内临时设置系统属性测试运行。测试结束后,该属性将恢复为之前的值。请注意,系统属性对整个JVM是全局的,并且可以以非事务方式进行修改,因此您应该以串行方式运行测试,而不是并行执行任何其他依赖于已修改属性的任务。

  • - run-listener =< CLASS_NAME> 扩展org.junit.runner.notification.RunListener的A(用户定义)类。创建此类的实例并将其添加到JUnit Runner,以便它将接收运行事件。有关更多信息,请参见RunListener。注意:这使用了test-classloader,因此需要在src / test或src / main中定义类,或者将其作为测试或编译依赖项包含在内。

  • - -include-categories =< CLASSES> 应包含的以逗号分隔的类别类名列表。只会运行包含一个或多个这些类别的测试。

  • - exclude-categories =< CLASSES> 以逗号分隔应排除的类别类名称列表。不会运行与这些类别中的一个或多个匹配的测试。

  • -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.

这篇关于如何更改Play Framework 2“测试”设置显示完整的堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆