放心进口没有解决

时间:2018-09-27 10:48:35

标签: rest-assured

我在我的POM中加入了放心的罐子,如下所示。

    <dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.0</version>
    </dependency>

But still the import statements are showing "The import io cannot be resolved".

如果我下载了放心的jar,并手动将其添加为外部jar,则错误消失了。

import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

我尝试删除

<scope>test</test> 

标记也在某些网站中建议使用。这不能解决问题。

import static io.restassured.RestAssured.*;

导入静态org.hamcrest.Matchers。*;

import org.testng.annotations.BeforeClass; 导入org.testng.annotations.Test;

导入io.restassured.RestAssured;

公共类OpenURL {

@BeforeClass
public void initPath() {

    RestAssured.baseURI = "http://localhost:9876";
}

/*******************************************************
 * Send a GET request to /api/f1/2016/drivers.json
 * and check that the answer has HTTP status code 200 
 ******************************************************/

@Test
public void checkResponseCodeForCorrectRequest() {

    given().
    when().
        get("/api/f1/2016/drivers.json").
    then().
        assertThat().
        statusCode(200);
}

}

我的完整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>REST</groupId>
  <artifactId>REST</artifactId>
  <version>0.0.1-SNAPSHOT</version>
   <dependencyManagement>
    <dependencies>
        <dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.9.10</version>
 </dependency>

                <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.4.5</version>
        </dependency>
        </dependencies>
          </dependencyManagement>
</project>

3 个答案:

答案 0 :(得分:2)

我怀疑“ dependencyManagement ”标记是否可以尝试以下操作

  <version>0.0.1-SNAPSHOT</version>
          <dependencies>
            <dependency>
                <groupId>io.rest-assured</groupId>
                <artifactId>rest-assured</artifactId>
                <version>3.0.0</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.testng/testng -->
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.9.10</version>
            </dependency>
            <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
                <version>2.4.5</version>
            </dependency>
        </dependencies>
</project>

答案 1 :(得分:1)

这是具有最新依赖性的完整POM.XML。

http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0.0

<groupId>com.student.app</groupId>
<artifactId>PaypalExmaples</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>PaypalExmaples</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

    <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>4.1.2</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.1.0</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy -->
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy</artifactId>
        <version>2.5.9</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.11</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.3.1</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.9</version>
    </dependency>

    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured-all</artifactId>
        <version>4.0.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.10.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.5.9</version>
        <type>pom</type>
    </dependency>

    <dependency>
        <groupId>org.skyscreamer</groupId>
        <artifactId>jsonassert</artifactId>
        <version>1.5.0</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.10.0.pr2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.scribe/scribe -->
    <dependency>
        <groupId>org.scribe</groupId>
        <artifactId>scribe</artifactId>
        <version>1.3.7</version>
    </dependency>


</dependencies>

答案 2 :(得分:-1)

import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

为我工作。在这里,我不使用POM文件