【问题标题】:running single specific scalatest in intellij idea在 intellij idea 中运行单个特定的 scalatest
【发布时间】:2016-07-12 00:36:06
【问题描述】:

在下面更新了完整的代码和孤立的问题

如果我有以下代码(scalatest 2.2.6、WordSpec、scala 2.11.8),我目前正在使用 intellij 14 Ultimate:

  "this code" when {

    "doing this" should {

      "know what is true" in {
        true shouldBe true
      }

      "know what is false" in {
        false shouldBe false
    }
  }

在intellij idea Ultimate 14(无需额外配置)中,如果我右键单击"know what is true" in {这一行,然后选择run test,它只会运行这一项测试

我刚刚升级到 2016.1 终极版(并尝试了 2016.2 RC),但这不再有效。如果我只点击一个测试,它只会运行文件中的所有测试。

如何在 2016.x 中解决此问题?

在下面编辑

如果我不使用标签,它只允许我运行单个选定的测试,但如果我使用标签,即使我选择运行特定的测试,它总是运行文件中的所有测试 - 这有效在 Intellij 14 中很好。

object TestTag extends Tag("com.me.test.tag")

class TestingSpec extends WordSpec with Matchers {

  "these tests allow single test to run" when {

    "doing this" should {

      "know what is true" in {
        true shouldBe true
      }

      "know what is false" in {
        false shouldBe false
      }
    }
  }

  "these tests DO NOT allow single test to run" when {

    "doing this" should {

      "know what is true" taggedAs TestTag in {
        true shouldBe true
      }

      "know what is false" taggedAs TestTag in {
        false shouldBe false
      }
    }
  }
}

【问题讨论】:

    标签: scala intellij-idea scalatest


    【解决方案1】:

    有一个名为Run Context Configuration 的命令,您可以通过按cmd+shift+a 并键入“运行上下文配置”来找到它。这将在您的光标下运行测试。

    如果您将光标放在when 块中,它将运行该块中的所有测试。

    或者有一个Debug Context Configuration,除了附加调试器之外,它做同样的事情。

    您可以在设置 > 键盘映射中将这些操作映射到您想要的任何键盘映射

    【讨论】:

    • cmd+shift+a 不能像上面编辑的那样工作
    • cmd+shift+a 只是按名称运行命令的一种方式,是对您不起作用的命令,还是您使用它运行的命令不起作用?
    • cmd+shift+a+"Run Contect Configuration"^+shift+F10right-mouse-click-Run-test 都做同样的事情。如果我使用标签,他们会运行所有测试,如果我不使用标签,他们只会运行一个选定的测试。使用标签运行一个选定测试的相同代码在 Intellij Idea 14 中运行良好
    • 嗯,那很奇怪,我也在使用带有标签的 scalatest,一切都对我有用。我假设您在调用命令之前将光标放在测试主体花括号内,对吗?
    猜你喜欢
    • 2014-02-16
    • 1970-01-01
    • 2020-01-27
    • 1970-01-01
    • 2019-05-23
    • 2016-04-26
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多