Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven未发现ScalaTest单元测试_Scala_Maven_Scalatest_Scalatest Maven Plugin - Fatal编程技术网

Maven未发现ScalaTest单元测试

Maven未发现ScalaTest单元测试,scala,maven,scalatest,scalatest-maven-plugin,Scala,Maven,Scalatest,Scalatest Maven Plugin,我有以下单元测试: import org.scalatest.FunSpec import org.scalatest.Matchers._ class MyClassSpec extends FunSpec { describe("MyClass"){ describe("Scenario 1"){ it("Condition 1") { true shouldEqual false } it("Condition 2"){

我有以下单元测试:

import org.scalatest.FunSpec
import org.scalatest.Matchers._

class MyClassSpec extends FunSpec {

  describe("MyClass"){
    describe("Scenario 1"){
      it("Condition 1") {
        true shouldEqual false
      }

      it("Condition 2"){
        true shouldEqual false
      }
    }
  }

}
当我运行maven测试时,这可以很好地编译,但是找不到测试。以下是输出:

[INFO] --- maven-surefire-plugin:2.7:test (default-test) @ project-name ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- scalatest-maven-plugin:1.0:test (test) @ project-name ---
Discovery starting.
Discovery completed in 202 milliseconds.
Run starting. Expected test count is: 0
DiscoverySuite:
Run completed in 236 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.
正如输出所示,我正在使用maven的scalatest插件。以下是my pom.xml的相关部分:

<!-- disable surefire -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.7</version>
    <configuration>
        <skipTests>true</skipTests>
    </configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <version>1.0</version>
    <configuration>
        <reportsDirectory>${project.build.directory}/scalatest-reports</reportsDirectory>
        <junitxml>junit</junitxml>
        <filereports>report.txt</filereports>
    </configuration>
    <executions>
        <execution>
            <id>test</id>
            <goals>
                <goal>test</goal>
            </goals>
        </execution>
    </executions>
</plugin>

org.apache.maven.plugins
maven surefire插件
2.7
真的
org.scalatest
scalatest maven插件
1
${project.build.directory}/scalatest报告
朱尼特
report.txt
测试
测试
我对这东西的设置还很陌生,所以我不确定是否还有其他东西我没有检查。如果我运行maven clean,然后运行maven测试,我会得到完全相同的结果。我使用的是ScalaTest版本3.0.1。我有另一个项目,测试也使用3.0.1成功运行(我复制了两个项目之间的所有我能找到的,甚至是远程相关的东西)。

您已经放置了
true
,用于跳过测试用例。因此,基本上您已禁用surefire,它用于:

Surefire插件在构建的测试阶段使用 生命周期来执行应用程序的单元测试。它产生 两种不同文件格式的报表纯文本文件(.txt)XML 文件(.xml)

使用以下内容更新您的pom:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
       <useFile>false</useFile>
       <disableXmlReport>true</disableXmlReport>
       <!-- If you have classpath issue like NoDefClassError,...-->
       <!-- useManifestOnlyJar>false</useManifestOnlyJar -->
       <includes>
           <include>**/*Test.*</include>
            <include>**/*Suite.*</include>
            <include>**/*Spec.*</include>
       </includes>
     </configuration>
</plugin>

org.apache.maven.plugins
maven surefire插件
2.18.1
假的
真的
**/*测试*
**/*套房*
**/*规格*
在include中,您必须提供测试文件的扩展名,并且可以更改pluggin的版本


谢谢

当然,这个问题似乎源于一些我认为不相关的信息,所以我没有把它包括在我原来的帖子中

我编写的源代码是用于单元测试的工具,因此我将其放在名称空间
my.cool.package.testUtilities
中。因此,单元测试位于
my.cool.package.testUtilities.test
中。将源代码移出
testUtilities
(到just
my.cool.package
)并将测试移动到just
my.cool.package.test
可以发现测试


作为java生态系统的新手(以前在.NET中的经验),我不确定这是否是测试运行程序的一些奇怪错误、预期行为,或者将文件移动到新名称空间的行为是否有其他作用,并且名称空间本身是无关的。因此,我不确定我从中学到了什么。

这一更改将要求所有测试都进行注释,而不是使用
scalatest maven plugin
。我知道maven插件可以工作,因为另一个项目能够成功地找到测试,你必须检查你的所有设置,因为pom中应该有一个不同的设置,或者如果可能的话,你可以共享这些设置以便我们查看。我在帖子中有我认为是
pom.xml
的相关部分-你还想看其他部分吗?是否还有其他文件可能包含一些相关信息?