2015-12-03 68 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> 

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