我刚刚建立了一个rest框架,并将其作为一个maven项目实现。我的pom.xml有下面提到的依赖项
<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>我的代码看起来就像
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所有依赖项来修复这个问题时,我会得到另一个错误:
java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpRequestBase当我添加另一个依赖项时,我会得到另一个错误,这个错误永远不会结束,也不会让人沮丧。有那么麻烦吗?我该怎么办才能一劳永逸?
发布于 2020-06-22 07:19:06
问题在于pom.xml文件中的Rest保证依赖关系的范围。
如果您从src/main/java运行放心测试,范围应该是compile,您的依赖性如下所示
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>如果您从src/test/java运行您放心的测试,范围应该是test,您的依赖将如下面所示
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>解决方案是将compile文件中的放心依赖项的作用域更改为pom.xml。
编译:这是默认范围,如果没有指定,则使用。编译依赖项在项目的所有类路径中都可用。此外,这些依赖项被传播到依赖项目。测试:此范围表示应用程序的正常使用不需要依赖项,只在测试编译和执行阶段可用。此范围不是传递性的。
https://sqa.stackexchange.com/questions/34093
复制相似问题