Scalatest Maven插件“未执行测试" [英] Scalatest Maven Plugin "no tests were executed"

查看:92
本文介绍了Scalatest Maven插件“未执行测试"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 scalatest

I'm trying to use scalatest and spark-testing-base on Maven for integration testing Spark. The Spark job reads in a CSV file, validates the results, and inserts the data into a database. I'm trying to test the validation by putting in files of known format and seeing if and how they fail. This particular test just makes sure the validation passes. Unfortunately, scalatest can't find my tests.

相关的pom插件:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <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}/surefire-reports</reportsDirectory>
                <wildcardSuites>com.cainc.data.etl.schema.proficiency</wildcardSuites>
            </configuration>
            <executions>
                <execution>
                    <id>test</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

这是测试类:

class ProficiencySchemaITest extends FlatSpec with Matchers with SharedSparkContext with BeforeAndAfter {
    private var schemaStrategy: SchemaStrategy = _
    private var dataReader: DataFrameReader = _

    before {
        val sqlContext = new SQLContext(sc)
        import sqlContext._
        import sqlContext.implicits._

        val dataInReader = sqlContext.read.format("com.databricks.spark.csv")
                                            .option("header", "true")
                                            .option("nullValue", "")
        schemaStrategy = SchemaStrategyChooser("dim_state_test_proficiency")
        dataReader = schemaStrategy.applySchema(dataInReader)
    }

    "Proficiency Validation" should "pass with the CSV file proficiency-valid.csv" in {
        val dataIn = dataReader.load("src/test/resources/proficiency-valid.csv")

        val valid: Try[DataFrame] = Try(schemaStrategy.validateCsv(dataIn))
        valid match {
            case Success(v) => ()
            case Failure(e) => fail("Validation failed on what should have been a clean file: ", e)
        }
    }
}

当我运行mvn test时,它找不到任何测试并输出以下消息:

When I run mvn test, it can't find any tests and outputs this message:

[INFO] --- scalatest-maven-plugin:1.0:test (test) @ load-csv-into-db ---
[36mDiscovery starting.[0m
[36mDiscovery completed in 54 milliseconds.[0m
[36mRun starting. Expected test count is: 0[0m
[32mDiscoverySuite:[0m
[36mRun completed in 133 milliseconds.[0m
[36mTotal number of tests run: 0[0m
[36mSuites: completed 1, aborted 0[0m
[36mTests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0[0m
[33mNo tests were executed.[0m

更新
通过使用:

UPDATE
By using:

<suites>com.cainc.data.etl.schema.proficiency.ProficiencySchemaITest</suites>

代替:

<wildcardSuites>com.cainc.data.etl.schema.proficiency</wildcardSuites>

我可以运行一个测试.显然,这是不理想的.通配符套件可能已损坏;我要在GitHub上打开一张票,看看会发生什么.

I can get that one Test to run. Obviously, this is not ideal. It's possible wildcardSuites is broken; I'm going to open a ticket on GitHub and see what happens.

推荐答案

这可能是因为项目路径中有一些空格字符. 删除项目路径中的空间,可以成功发现测试. 希望有帮助.

This is probably because there are some space characters in the project path. Remove space in project path and the tests can be discovered successfully. Hope this help.

这篇关于Scalatest Maven插件“未执行测试"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆