我有一个Maven程序,可以正常编译。 我有这个scala类./src/test/java/ResearchTest.scala
import org.junit.Test
class ResearchTest
{
@Test
def justAnExample(): Unit = {
System.out.println("This test method should be running SCALA")
}
}
当我运行mvn clean test时,它不运行任何测试,这是输出:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< poc:webIntTest11111 >-------------------------
[INFO] Building webIntTest11111 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from paypal-snapshots: http://nexus.paypal.com/nexus/content/repositories/snapshots/com/paypal/risk/ars/url-udf/0.0.1-SNAPSHOT/maven-metadata.xml
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ webIntTest11111 ---
[INFO] Deleting /Users/drimoch/IdeaProjects/webIntTest11111/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ webIntTest11111 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ webIntTest11111 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ webIntTest11111 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ webIntTest11111 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/drimoch/IdeaProjects/webIntTest11111/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ webIntTest11111 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.356 s
[INFO] Finished at: 2018-10-14T16:46:49+03:00
[INFO] ------------------------------------------------------------------------
我也有这个java类。/src/test/java/Tests.java:
import org.junit.Test;
public class Tests {
@Test
public void justAnExample() {
System.out.println("This test method should be run JAVA");
}
}
现在我运行mvn clean测试时,它将运行此测试。
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< poc:webIntTest11111 >-------------------------
[INFO] Building webIntTest11111 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from paypal-snapshots: http://nexus.paypal.com/nexus/content/repositories/snapshots/com/paypal/risk/ars/url-udf/0.0.1-SNAPSHOT/maven-metadata.xml
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ webIntTest11111 ---
[INFO] Deleting /Users/drimoch/IdeaProjects/webIntTest11111/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ webIntTest11111 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ webIntTest11111 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ webIntTest11111 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ webIntTest11111 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/drimoch/IdeaProjects/webIntTest11111/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ webIntTest11111 ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running Tests
This test method should be run JAVA
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.054 s - in Tests
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.514 s
[INFO] Finished at: 2018-10-14T16:59:10+03:00
[INFO] ------------------------------------------------------------------------
我想在scala中运行测试,应该更改什么?
这也是我的pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>poc</groupId>
<artifactId>webIntTest11111</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.paypal.risk.ars.bigdata.webintl</groupId>
<artifactId>webintl-services</artifactId>
<version>2.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>com.paypal.risk.ars.zonkey</groupId>
<artifactId>spark-utils</artifactId>
<type>test-jar</type>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.paypal.risk.ars.bigdata.webintl</groupId>
<artifactId>webintl-services</artifactId>
<version>2.5.0</version>
<type>test-jar</type>
</dependency>
</dependencies>
</project>
答案 0 :(得分:0)
运行Maven测试时。您实际上正在使用surefire插件。默认情况下,Surefire插件将自动包含具有以下通配符模式的所有测试类:
我建议您将build.sbt文件添加到项目中,并使用sbt处理scala类。但是,如果需要使用Maven进行此操作,则需要将scalatest-maven-plugin添加到pom中,将scala测试类移至src / test / scala。然后您应该可以使用Maven进行测试。