【问题标题】:How to run Scalatest with JUnit tests using maven plugin如何使用 Maven 插件通过 JUnit 测试运行 Scalatest
【发布时间】:2016-01-20 02:54:42
【问题描述】:

我正在使用 scala to java maven project 编写一些测试。我想用 maven 插件运行这些测试,但我也希望其余的 JUnit 测试也能运行。 问题是根据this guidelines 我必须禁用 surefire 。 我有运行 scalatest 和 junit 测试的解决方案吗?

【问题讨论】:

    标签: scala maven junit scalatest maven-surefire-plugin


    【解决方案1】:

    您可以使用 maven surefire 插件运行您的 scalatests。您只需通过注释指定使用 JUnitRunner 即可运行您的 scalatest。

    @RunWith(classOf[JUnitRunner])
    class MyTest extends FunSuite with Matchers {
      test("foobar") {
        true should be(true)
      }
    }
    

    【讨论】:

    • 你知道这种情况下如何配置scalatest运行吗?例如确保有记者或配置标签?
    【解决方案2】:

    如上所述,您需要对规范进行注释才能使用 JUnit 运行器。

    @RunWith(classOf[JUnitRunner])
    class MyTest extends FunSuite with Matchers {
      test("foobar") {
        true should be(true)
      }
    }
    

    您还需要配置 surefire 插件以包含规范。这是我的配置:

    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>${maven-surefire-plugin.version}</version>
      <dependencies>
        <dependency>
          <groupId>org.apache.maven.surefire</groupId>
          <artifactId>surefire-junit47</artifactId>
          <version>${maven-surefire-plugin.version}</version>
        </dependency>
      </dependencies>
      <configuration>
        <includes>
          <include>**/*Test.*</include>
          <include>**/*Specification.*</include>
        </includes>
      </configuration>
    </plugin>
    

    确保将任何模式添加到包含以匹配您的测试类名称。

    别忘了从maven central引入scalatest

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 2016-12-06
      • 2012-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-23
      相关资源
      最近更新 更多