首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >scala代码上的maven测试返回成功构建,但没有要运行的测试

scala代码上的maven测试返回成功构建,但没有要运行的测试
EN

Stack Overflow用户
提问于 2017-03-31 06:16:58
回答 1查看 453关注 0票数 1

我在使用mvn test在我的maven scala代码中运行测试代码时遇到了问题。以下是设置:

代码语言:javascript
复制
.
├── pom.xml
├── run
└── src
    ├── main
    │   └── scala
    │       └── com
    │           └── myCompany
    │               └── scala
    │                   └── MaxPrice.scala
    ├── resources
    │   └── JCudaMultiplyBy2.ptx
    └── test
        ├── resources
        │   └── JCudaMultiplyBy2.ptx
        └── scala
            └── MyTest.scala

JCudaMultiplyBy2.ptx是将在MyTest.scala中使用的文件。

这是我的pom.xml:

代码语言:javascript
复制
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myCompany.scala</groupId>
  <artifactId>sparkExample</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <properties>
    <scala.version>2.10.5</scala.version> <!-- Well we can use 2.11 scala, but scala-maven-plugin may have issue with that, so if to use mvn -q scala:run, then keep 2.10 scala, otherwise, have to spark-submit -->
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala.version}</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.4</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.scala-tools</groupId>
      <artifactId>maven-scala-plugin</artifactId>
      <version>2.11</version>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-core_2.10</artifactId>
      <version>1.6.1</version>
    </dependency>
    <dependency>
      <groupId>org.jcuda</groupId>
      <artifactId>jcuda</artifactId>
      <version>0.8.0</version>
    </dependency>
    <dependency>
      <groupId>org.jcuda</groupId>
      <artifactId>jcublas</artifactId>
      <version>0.8.0</version>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
          <args>
            <!--arg>-target:jvm-1.5</arg-->
          </args>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.8.1</version>
        <configuration>
                    <includes>
                        <include>**/*Spec.class</include>
                        <include>**/*Test.class</include>
                    </includes>
                </configuration>
      </plugin>
   </plugins>
  </build>
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <configuration>
          <scalaVersion>${scala.version}</scalaVersion>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
</project>

本地代码与本地代码相同,如果我运行mvn compile,然后运行mvn -q scala:run -DmainClass=com.myCompany.scala.MaxPrice -DaddArgs=“-q*”,它可以完美地工作。现在我将MaxPrice.scala的对象名称更改为MyTest,并将其文件名更改为MyTest.scala。将MyTest.scala放在src/test/scala下并运行mvn test,它不起作用,并给出以下结果:

代码语言:javascript
复制
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.myCompany.scala:sparkExample:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.scala-tools:maven-scala-plugin is missing. @ line 48, column 15
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building sparkExample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ sparkExample ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/yuxin/OwensGroup/MavenPract/maven-sparkJcublas/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ sparkExample ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-scala-plugin:2.15.2:compile (default) @ sparkExample ---
[INFO] Checking for multiple versions of scala
[WARNING]  Expected all dependencies to require Scala version: 2.10.5
[WARNING]  com.myCompany.scala:sparkExample:1.0-SNAPSHOT requires scala version: 2.10.5
[WARNING]  com.twitter:chill_2.10:0.5.0 requires scala version: 2.10.4
[WARNING] Multiple versions of scala libraries detected!
[INFO] includes = [**/*.java,**/*.scala,]
[INFO] excludes = []
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ sparkExample ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ sparkExample ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-scala-plugin:2.15.2:testCompile (default) @ sparkExample ---
[INFO] Checking for multiple versions of scala
[WARNING]  Expected all dependencies to require Scala version: 2.10.5
[WARNING]  com.myCompany.scala:sparkExample:1.0-SNAPSHOT requires scala version: 2.10.5
[WARNING]  com.twitter:chill_2.10:0.5.0 requires scala version: 2.10.4
[WARNING] Multiple versions of scala libraries detected!
[INFO] includes = [**/*.java,**/*.scala,]
[INFO] excludes = []
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.8.1:test (default-test) @ sparkExample ---
[INFO] Surefire report directory: /home/yuxin/OwensGroup/MavenPract/maven-sparkJcublas/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.202 s
[INFO] Finished at: 2017-03-30T14:52:29-07:00
[INFO] Final Memory: 25M/592M
[INFO] ------------------------------------------------------------------------

此外,如果我运行mvn test -Dtest=MyTest,它仍然会给出相同的结果:没有要运行的测试。

有谁有主意吗?我已经找了很久,但还是找不到答案,救命!

EN

回答 1

Stack Overflow用户

发布于 2017-03-31 20:58:06

显然,作者认为您应该使用scala-maven-plugin而不是maven-scala-plugin (请参阅here)。

更重要的是,根据(全能的) documentation,要运行scala测试,您应该禁用surefire插件:

要使用ScalaTest Maven插件,您需要禁用SureFire并启用ScalaTest。

在surefire插件的配置部分添加:

代码语言:javascript
复制
<skipTests>true</skipTests>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43129317

复制
相关文章

相似问题

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