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

时间:2017-09-12 16:54:41

标签: java eclipse maven junit

我正在尝试这个guide来学习整合Maven,Jenkins和Selenium。指南的问题是时间的浪费和严重的兼容性问题。我一直试图调试它,但是现在我在第15步,由于这个问题不能再进一步了解:

  

T E S T S.   -------------------------------------------------- -----运行example.NewTest测试运行:1,失败:1,错误:0,跳过:0,时间   已过去:2.255秒<<< FAILURE!

     

结果:

     

测试失败:example.NewTest.testEasy():org / testng / AssertJUnit

     

测试运行:1,失败:1,错误:0,跳过:0

     

[INFO]   -------------------------------------------------- ---------------------- [INFO] BUILD FAILURE [INFO]   -------------------------------------------------- ---------------------- [INFO]总时间:9.145s [INFO]完成日期:Tue Sep 12 09:42:36 PDT   2017 [信息]最终记忆:7M / 17M [INFO]   -------------------------------------------------- ---------------------- [错误]无法执行目标   org.apache.maven.plugins:Maven的万无一失,插件:2.12:测试   项目WDTest上的(默认测试):存在测试失败。 [错误]   [错误]请参阅   C:\ ST \ kpimuiws-build-changes \ WDTest \ target \ surefire-reports for   个别测试结果。

surefire报告文本文件显示:

  

测试集:example.NewTest

     

测试运行:1,失败:1,错误:0,跳过:0,经过的时间:2.255秒<<<失败! example.NewTest.testEasy()经过的时间:2.25秒

     

<<<失败! java.lang.NoClassDefFoundError:org / testng / AssertJUnit   at example.NewTest.testEasy(NewTest.java:34)引起:   java.lang.ClassNotFoundException:org.testng.AssertJUnit
  在java.net.URLClassLoader.findClass(未知来源)at   java.lang.ClassLoader.loadClass(未知来源)at   sun.misc.Launcher $ AppClassLoader.loadClass(未知来源)at   java.lang.ClassLoader.loadClass(未知来源)... 19更多

这是我的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();          
        }       
}   

1 个答案:

答案 0 :(得分:1)

AssertJUnit是TestNG库的一部分。你能尝试在你的POM中加入TestnG吗?

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