gpt4 book ai didi

java - Maven 测试 - java.lang.ClassNotFoundException : org. testng.AssertJUnit

转载 作者:行者123 更新时间:2023-12-02 12:16:00 24 4
gpt4 key购买 nike

我正在尝试这个guide学习集成 Maven、Jenkins 和 Selenium。指南的问题是时间的侵 eclipse 和严重的兼容性问题。我一直在尝试调试它,但现在我处于第 15 步,由于这个问题无法进一步进行:

T E S T S------------------------------------------------------- Running example.NewTest Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Timeelapsed: 2.255 sec <<< FAILURE!

Results :

Failed tests: example.NewTest.testEasy(): org/testng/AssertJUnit

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[INFO]------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO]------------------------------------------------------------------------ [INFO] Total time: 9.145s [INFO] Finished at: Tue Sep 12 09:42:36 PDT2017 [INFO] Final Memory: 7M/17M [INFO]------------------------------------------------------------------------ [ERROR] Failed to execute goalorg.apache.maven.plugins:maven-surefire-plugin:2.12:test(default-test) on project WDTest: There are test failures. [ERROR][ERROR] Please refer toC:\ST\kpimuiws-build-changes\WDTest\target\surefire-reports for theindividual test results.

surefire 报告文本文件显示:

Test set: example.NewTest

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 2.255 sec <<< FAILURE! example.NewTest.testEasy() Time elapsed: 2.25 sec

<<< FAILURE! java.lang.NoClassDefFoundError: org/testng/AssertJUnitat example.NewTest.testEasy(NewTest.java:34) Caused by:java.lang.ClassNotFoundException: org.testng.AssertJUnit
at java.net.URLClassLoader.findClass(Unknown Source) atjava.lang.ClassLoader.loadClass(Unknown Source) atsun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) atjava.lang.ClassLoader.loadClass(Unknown Source) ... 19 more

这是我的 pom;

<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>WDTest</groupId>
<artifactId>WDTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<inherited>true</inherited>
<configuration>
<suiteXmlFile>testng.xml</suiteXmlFile>

</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>

</dependencies>
</project>

这是我的 NewTest.java

package example;        

import java.io.File;

import org.testng.annotations.Test;
//import org.testng.Assert;
import org.testng.AssertJUnit;
//import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
//import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;






public class NewTest {
//private WebDriver driver;

File pathBinary = new File("C:\\Users\\T667627\\AppData\\Local\\MozillaFirefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(firefoxBinary, firefoxProfile);

@Test
public void testEasy() {
driver.get("http://demo.guru99.com/selenium/guru99home/");
String title = driver.getTitle();
AssertJUnit.assertTrue(title.contains("Demo Guru99 Page"));
}
@BeforeTest
public void beforeTest() {
driver = new FirefoxDriver();
}
@AfterTest
public void afterTest() {
driver.quit();
}
}

最佳答案

AssertJUnit 是 TestNG 库的一部分。您可以尝试将 TestnG 包含在您的 POM 中吗?

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>

关于java - Maven 测试 - java.lang.ClassNotFoundException : org. testng.AssertJUnit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46181870/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com