2015-12-03 67 views
0

當我嘗試通過[mvn clean install -DskipTests]通過控制檯構建項目時出現錯誤。我在測試中使用了testNG SoftAssert,並在測試類中添加了一個導入導入org.testng.asserts.SoftAssert,但看起來像maven沒有看到該包。從控制檯 錯誤:Maven編譯錯誤[軟件包org.testng.asserts不存在]

包org.testng.asserts不存在

我的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>com.atlassian</groupId> 
<artifactId>tests</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>jar</packaging> 
<name>confluence</name> 
<url>http://maven.apache.org</url> 
<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 
<dependencies> 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.1.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>2.48.2</version> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.17</version> 
    </dependency> 
</dependencies> 
<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.1</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.16</version> 
      <configuration> 
       <suiteXmlFiles> 
        <suiteXmlFile>testng.xml</suiteXmlFile> 
       </suiteXmlFiles> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

+0

maven是否可以識別其他'TestNG'類?就像你使用'@ Test'時一樣,它是否會給出類似的錯誤? – MKay

回答

0

這樣的錯誤沒有你正在嘗試使用的類。在這種情況下,您正在使用TestNG version 6.1.1,沒有包org.testng.asserts。嘗試使用以下版本, 另外,如果您要求IDE包含TestNG library,它將不會導致錯誤導入SoftAsserts。這個庫肯定比pom.xml提到的版本要高。儘量保持pom.xml &您的IDE的testNG plugin相同的版本,以避免這種變化的行爲。

<dependency> 
    <groupId>org.testng</groupId> 
    <artifactId>testng</artifactId> 
    <version>6.8.8</version> 
</dependency> 

以上版本肯定是有效的。試一試。