首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >请放心,为什么在尝试使用Rest安全自动化apis时会出现重复的错误?

请放心,为什么在尝试使用Rest安全自动化apis时会出现重复的错误?
EN

Stack Exchange QA用户
提问于 2018-06-05 10:22:29
回答 1查看 1.5K关注 0票数 0

我刚刚建立了一个rest框架,并将其作为一个maven项目实现。我的pom.xml有下面提到的依赖项

代码语言:javascript
复制
  <dependencies>
  <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.2</version>
    <scope>test</scope>
</dependency>
  
  
  <!-- To parse json Document -->
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>json-path</artifactId>
    <version>3.0.2</version>
</dependency>


<!-- To validate that a json response conforms to a json schema -->
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>json-schema-validator</artifactId>
    <version>3.0.2</version>
</dependency>


<!-- To parse xml document -->
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>xml-path</artifactId>
    <version>3.0.2</version>
</dependency>


<!-- Testing framework -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.10</version>
    <scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.hamcrest/java-hamcrest Used for Regex -->
<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>java-hamcrest</artifactId>
    <version>2.0.0.0</version>
    <scope>test</scope>
</dependency>
  
</dependencies>  
</project>

我的代码看起来就像

代码语言:javascript
复制
import static io.restassured.RestAssured.*;

import org.testng.annotations.Test;

public class LrnAsServiceApis {
    

    @Test
    public void trackvialrnumber() {
        
        given().get("lt-api.delta.com/v1/fulltrack/ABCD").then().log().all();
    }

但是当我以TestNg的形式运行它时,我会得到错误:java.lang.NoClassDefFoundError: groovy/lang/GroovyObject

当我试图通过添加groovy所有依赖项来修复这个问题时,我会得到另一个错误:

代码语言:javascript
复制
java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpRequestBase

当我添加另一个依赖项时,我会得到另一个错误,这个错误永远不会结束,也不会让人沮丧。有那么麻烦吗?我该怎么办才能一劳永逸?

EN

回答 1

Stack Exchange QA用户

发布于 2020-06-22 07:19:06

问题在于pom.xml文件中的Rest保证依赖关系的范围。

如果您从src/main/java运行放心测试,范围应该是compile,您的依赖性如下所示

代码语言:javascript
复制
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.2</version>
    <scope>compile</scope>
</dependency>

如果您从src/test/java运行您放心的测试,范围应该是test,您的依赖将如下面所示

代码语言:javascript
复制
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.2</version>
    <scope>test</scope>
</dependency>

解决方案是将compile文件中的放心依赖项的作用域更改为pom.xml

参考资料:https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_作用域

编译:这是默认范围,如果没有指定,则使用。编译依赖项在项目的所有类路径中都可用。此外,这些依赖项被传播到依赖项目。测试:此范围表示应用程序的正常使用不需要依赖项,只在测试编译和执行阶段可用。此范围不是传递性的。

票数 1
EN
页面原文内容由Stack Exchange QA提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://sqa.stackexchange.com/questions/34093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档