【问题标题】:maven test on scala code return successful build but There are no tests to runscala代码上的maven测试返回成功的构建,但没有要运行的测试
【发布时间】:2017-03-30 22:16:57
【问题描述】:

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

.
├── 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:

<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>

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

[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,它仍然给出相同的结果:没有要运行的测试。

有人有想法吗?找了好久没找到答案,求救!

【问题讨论】:

    标签: scala maven testing


    【解决方案1】:

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

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

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

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

    <skipTests>true</skipTests>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-21
      • 1970-01-01
      • 2019-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-19
      相关资源
      最近更新 更多