首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >让ScalaTest从maven.运行我的测试

让ScalaTest从maven.运行我的测试
EN

Stack Overflow用户
提问于 2017-04-28 00:01:15
回答 1查看 2.8K关注 0票数 1

我直接从the documentation把这个添加到我的pom.xml中

代码语言:javascript
复制
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.7</version>
    <configuration>
      <skipTests>true</skipTests>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <version>1.0</version>
    <configuration>
      <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
      <junitxml>.</junitxml>
      <filereports>TestSuite.txt</filereports>
    </configuration>
    <executions>
      <execution>
        <id>test</id>
        <goals>
          <goal>test</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

运行mvn test会给我带来:

代码语言:javascript
复制
Discovery starting.
Discovery completed in 265 milliseconds.
Run starting. Expected test count is: 0
DiscoverySuite:
Run completed in 283 milliseconds.
Total number of tests run: 0
Suites: completed 1, aborted 0
Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
No tests were executed.

但是,在src/test/scala下有几个测试应该已经被发现并运行。

我甚至尝试过运行mvn test-compile compile,只是想看看是否出现了什么。结果不出所料:

代码语言:javascript
复制
[INFO] Nothing to compile - all classes are up to date

那么,为什么它们没有被发现呢?我的文件都被命名为*Test.scala,并且像在scalatest documentation中那样编写。

EN

回答 1

Stack Overflow用户

发布于 2017-04-28 02:44:58

在我当前的项目中,我们在pom.xml中有以下配置:

代码语言:javascript
复制
 <plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.2.2</version>
    <executions>
      <execution>
        <id>compile</id>
        <goals>
          <goal>compile</goal>
        </goals>
        <phase>compile</phase>
      </execution>
      <execution>
        <id>test-compile</id>
        <goals>
          <goal>testCompile</goal>
        </goals>
        <phase>test-compile</phase>
      </execution>
      <execution>
        <phase>process-resources</phase>
        <goals>
          <goal>compile</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

  <plugin>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <version>1.0</version>
    <configuration>
      <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
      <stdout>W</stdout>
    </configuration>
    <executions>
      <execution>
        <id>scala-test</id>
        <goals>
          <goal>test</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

由于很容易猜测,第一个插件负责编译和资源处理,而第二个插件只在测试目标期间运行它们。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43662673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档