IntelliJ Idea 中的 ScalaTest 控制台输出

发布于 2024-12-09 18:52:19 字数 323 浏览 1 评论 0原文

我对如何让 IDEA 将测试中的任何内容输出到控制台感到非常沮丧。我尝试过不同版本的 Scala、ScalaTest 和 IDEA - 没有任何帮助。目前我的设置是:scala-2.10.0-snapshot,scalatest_2.9.1-1.6.1,idea 110.3。该项目由maven管理。有人可以帮忙吗?我期待看到类似的内容: http://www.scalatest.org/getting_started_with_feature_spec

I'm pretty frustrated with how to make IDEA output anything from the tests to console. I've tried different versions of Scala, ScalaTest and IDEA - nothing helps. Currently my setup is: scala-2.10.0-snapshot, scalatest_2.9.1-1.6.1, idea 110.3. The project is managed by maven. Could anyone please help? I'm expecting to see something like that: http://www.scalatest.org/getting_started_with_feature_spec

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘你却要生生世世 2024-12-16 18:52:19

看来是Idea Scala插件的问题。后来的构建开始将一些输出放入控制台,但并不是人们所期望的一切。有关该插件的最新版本,请查看 http://confluence .jetbrains.net/display/SCA/Scala+Plugin+Nightly+Builds+for+Nika

Looks like it's a problem of Idea Scala plugin. Later builds start putting some output into the console, but not everything one should expect. For latest releases of the plugin check out http://confluence.jetbrains.net/display/SCA/Scala+Plugin+Nightly+Builds+for+Nika

岛歌少女 2024-12-16 18:52:19

我刚刚经历了整个“受到 IDEA 惩罚”的事情,我为您提供了这个解决方案...

添加 Logbackslf4s 到您的 POM:

<dependency>
    <groupId>com.weiglewilczek.slf4s</groupId>
    <artifactId>slf4s_${scala.version}</artifactId>
    <version>1.0.7</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>0.9.30</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>0.9.30</version>
</dependency>

注意:
我在 slf4s artifactId 中使用了 ${scala.version} - 确保您已经定义了它或将其替换为 2.9.1 或类似的东西。
另外 - 您还需要可用于依赖项的 scala-tools 存储库 - 我假设您会拥有它,因为我认为您需要它来编译。

然后将一个名为 logback.xml 的文件添加到您的资源文件夹中,其中包含以下内容:

<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date,%d{HH:mm:ss.SSS},%thread,%-5level,%logger{36},%line,%msg%n</pattern>
        </encoder>
    </appender>

    <root level="TRACE">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>

我的模式可能有点奇怪 - 它实际上来自一个文件附加程序,该文件附加程序将其以 CSV 格式输出,我可以轻松地在 Excel 中打开并绘制图表。< /em>

然后像这样扩展应用程序中的特征 Logging:

import swing._
import com.weiglewilczek.slf4s.Logging

object App extends SwingApplication with Logging {

    override def startup(args: Array[String]) {

        logger.info("Starting init...")
    }
}

并且信息消息“Starting init...”以及一堆其他内容应该出现在控制台窗口中。

Logback 和 slf4s 是我链接到的主题。

重要且很棒:

我不记得它叫什么,但您用来发布消息的日志记录方法都有像 info(message: => String) 这样的签名 - 正如您在 logger.scala

这意味着如果配置文件中未启用相关级别的日志记录,您传递给它们的表达式或块将根本不会被执行。

因此,它仅在关闭时向代码添加一个方法调用和一个标志检查 - 这是非常好的恕我直言:)

希望有所帮助,
赛斯.

I've just been through the whole "getting punished by IDEA" thing and I have this solution for you...

Add Logback and slf4s to your POM:

<dependency>
    <groupId>com.weiglewilczek.slf4s</groupId>
    <artifactId>slf4s_${scala.version}</artifactId>
    <version>1.0.7</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>0.9.30</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>0.9.30</version>
</dependency>

NOTES:
I've used ${scala.version} in the slf4s artifactId - make sure you have this defined or replace it with 2.9.1 or something like that.
Also - you'll need the scala-tools repo available for dependencies too - which I'm assuming you'll have as I think you need it to compile.

Then add a file called logback.xml to your resources folder containing this:

<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date,%d{HH:mm:ss.SSS},%thread,%-5level,%logger{36},%line,%msg%n</pattern>
        </encoder>
    </appender>

    <root level="TRACE">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>

My pattern there is potentially a bit weird - it's actually from a file appender that spits it out as a CSV I can open and graph in Excel easily.

Then extend the trait Logging in your app like so:

import swing._
import com.weiglewilczek.slf4s.Logging

object App extends SwingApplication with Logging {

    override def startup(args: Array[String]) {

        logger.info("Starting init...")
    }
}

And the info message, "Starting init..." with a bunch of other stuff should appear in the console window.

Logback and slf4s are topics that I've linked to.

IMPORTANT AND AWESOME:

I can't remember what it's called but the logging methods you use to post messages all have signatures like info(message: => String) - as you can see in logger.scala.

This means the expression or block you pass to them will not get executed at all if the relevant level of logging isn't enabled in the config file.

So it only adds a method call and a flag-check to the code when it's turned off - which is pretty sweet imho :)

Hope that helps,
Seth.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文