Scalatest Maven Plugin "no tests were executed"
Asked Answered
K

6

11

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.

Relevant pom plugins:

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

And here's the test class:

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

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>

Instead of:

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

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.

Kitchenware answered 1/8, 2016 at 13:35 Comment(4)
Where is ProficiencySchemaITest located?Hjerpe
src/test/scala/com/cainc/data/etl/schema/proficiency/ProficiencySchemaITest.scala. I do have in my pom: <sourceDirectory>src/main/scala</sourceDirectory> <testSourceDirectory>src/test/scala</testSourceDirectory>Kitchenware
I can also see in target/ that the .class files were created.Kitchenware
I have this same issue without using wildcardSuites, so the issue might be deeper.Righteousness
P
4

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.

Pauperism answered 16/2, 2017 at 8:46 Comment(3)
Full path: C:\dev\projects\nintendo\spark-data-load\src\main\blah\blah\blahKitchenware
The problem with spaces in the project path should be fixed in this PR: github.com/scalatest/scalatest-maven-plugin/pull/37Aekerly
By Removing spaces from path, it works for me after two Days :)Dice
T
1

Try excluding junit as a transitive dependency. Works for me. Example below, but note the Scala and Spark versions are specific to my environment.

   <dependency>
        <groupId>com.holdenkarau</groupId>
        <artifactId>spark-testing-base_2.10</artifactId>
        <version>1.5.0_0.6.0</version>
        <scope>test</scope>
        <exclusions>
            <!-- junit is not compatible with scalatest -->
            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>
        </exclusion>
    </dependency>
Triacid answered 22/2, 2017 at 17:38 Comment(0)
S
1

With me, it's because I wasn't using the following plugin:

<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.8</arg>
          </args>
        </configuration>
      </plugin>
Seawards answered 16/6, 2018 at 22:28 Comment(1)
You saved me a day.Innkeeper
J
1

The issue I had with tests not getting discovered came down to the fact that the tests are discovered from the class files, so to make the tests get discovered I need to add <goal>testCompile</goal> to scala-maven-plugin goals.

Jewelry answered 15/1, 2020 at 17:19 Comment(0)
E
0

In my case it's because of the nesting of tests inside the test directory and using the <memberOnlySuites> configuration. <memberonlySuites> only looks out for the test files in the give package / directory. Instead use <wildcardSuites> which will look into a package / directory and all it's subdirectories.

This happens quiet often when you are adding more tests to your test suite and organising them in a more structured manner.

Ella answered 21/6, 2022 at 5:19 Comment(0)
B
-1

Cause: Maven plugins does not compile your test code whenever you run mvn commands.

Work around:

Run scala tests using your IDE which will compile the test code and saves it in target directory. And when next time you run mvn test or any maven command which internally triggers maven's test cycle it should run the scala tests

Bomb answered 7/4, 2020 at 4:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.