java - 导入静态 io.restassured.RestAssured.*;不工作
问题描述
我正在尝试为 API 测试编写一个 BDD 框架。导入静态 io.restassured.RestAssured.*;不工作。此外,当我使用 given() 关键字时,它会引发错误。我已经添加了各自的 Maven 依赖项,静态导入不起作用。不了解需要添加什么或添加的依赖项需要更改。
代码片段:包restApi;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matcher.*;
public class Test1_BasicFeature
{
@Test
public void testStatusCode()
{
given().
}
}
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.servicetest</groupId>
<artifactId>maven-servicetest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/json-path -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>3.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>3.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/xml-path -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>xml-path</artifactId>
<version>3.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>2.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
解决方案
利用
import static io.restassured.*;
import static org.hamcrest.*;
代替
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matcher.*;
推荐阅读
- ios - iOS 系统库即使不添加到“框架、库和嵌入式内容”也可以导入
- r - 仅使用 Signif 提取变量和系数。R 小于 0.05
- javascript - Webpack 文件加载器未在生产构建中加载资产文件夹
- ruby-on-rails - Ruby graphql 如何定义不是 Active Record 的对象类型?
- git - 为什么我的 Git 无法通过终端进行更新?
- firebase - 实时数据库是否具有像 ServerValue.increment 这样的 Flutter 原子增量方法?
- firebase - Flutter RealtimeDatabase ServerValue.Increment
- javascript - 如何使用选项作为参数初始化hammerJS对象
- r - 将嵌套的 for 循环转换为 foreach
- python - 带有 ytsearchdate 的 youtube-dl 仅返回 20 个结果