我正在尝试使用 Maven 在终端中运行我的单元测试。
当我运行 mvn clean test
或 mvn test
时,我得到以下输出:
user@user:~/Documents/git/projectname$ mvn test
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building project name 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ projectname ---
[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.1:compile (default-compile) @ projectname ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ projectname ---
[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.1:testCompile (default-testCompile) @ projectname ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ projectname ---
[INFO] Surefire report directory: /home/user/Documents/git/QA-projectname/target/surefire-reports
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.pom
[INFO] Failure detected.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.258 s
[INFO] Finished at: 2018-06-13T15:36:31-06:00
[INFO] Final Memory: 13M/54M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project projectname: Unable to generate classpath: org.apache.maven.artifact.resolver.ArtifactResolutionException: Unable to get dependency information for org.apache.maven.surefire:surefire-junit4:jar:2.12.4: Failed to retrieve POM for org.apache.maven.surefire:surefire-junit4:jar:2.12.4: Could not transfer artifact org.apache.maven.surefire:surefire-junit4:pom:2.12.4 from/to central (https://repo.maven.apache.org/maven2): java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
[ERROR] org.apache.maven.surefire:surefire-junit4:jar:2.12.4
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false)
[ERROR] Path to dependency:
[ERROR] 1) dummy:dummy:jar:1.0
[ERROR]
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
我也曾尝试使用 mvn test -Dtest=testname
运行单个测试,但我遇到了同样的错误。
这是我的 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupidhere</groupId>
<artifactId>artifactidhere</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire</artifactId>
<version>2.21.0</version>
<type>pom</type>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<name>Small Store Regression</name>
<description>description here</description>
</project>
这是我的一个测试示例:
package loginPurchase;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import PageObjects.CartScreen;
import PageObjects.HomeScreen;
import testBase.TestBase;
import java.math.BigDecimal;
import static org.junit.Assert.assertTrue;
public class ProductTaxPurchases extends TestBase {
@Before
public void setUp() throws Exception {
mobileSetup();
}
@AfterClass
public static void tearDown() throws Exception {
mdriver.quit();
mdriver = null;
}
//The purpose of this test is to add a taxed product to a cart and verify the taxes are correct | and purchase by CC
@Test
public void purchaseTaxedProductByCredit() throws InterruptedException {
HomeScreen hs = new HomeScreen(mdriver);
CartScreen cs = new CartScreen(mdriver);
hs.clickMenu("TestMenuB")
.clickMenuItem("ChrisTaxProduct");
String subTotal = cs.getSubTotal();
String taxAmount = cs.getTax();
String grandTotal = cs.getGrandTotal();
BigDecimal currentSubTotal = new BigDecimal(subTotal);
BigDecimal currentTaxTotal = new BigDecimal(taxAmount);
BigDecimal currentGrandTotal = new BigDecimal(grandTotal);
BigDecimal expectedGrandTotal = currentSubTotal.add(currentTaxTotal);
assertTrue(currentGrandTotal.compareTo(expectedGrandTotal) == 0);
cs.clickPayByCreditCard()
.swipeApprovedCard()
.clickNoReceipt();
}
第二次编辑:
这是 mvn dependency::tree
[ERROR] No plugin found for prefix 'dependency' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/home/chris/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
第三次编辑:
我可以在我的 Windows 10 机器上成功运行 mvn clean test
并且它按预期工作。我的 Ubuntu 18.04 机器上存在这个问题。
我能做些什么来解决这个问题?我通常在 intellij idea 中运行我的测试,它们运行得很好。但我需要准备好这些测试,以便在 Microsoft App Center 中上传。
最佳答案
Ubuntu 18.04 存在该问题。
我运行了 sudo rm/etc/ssl/certs/java/cacerts 然后运行了 sudo update-ca-certificates -f 这解决了我在 kubuntu 18.04 中的问题。
关于java - 无法通过终端运行 Maven 测试 |未能执行目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50846800/