错误为“无法解析类型 org.hamcrest.Matcher”

问题描述 投票:0回答:10

enter image description here

我收到错误为

无法解析 org.hamcrest.Matcher 类型。它是从所需的.class文件间接引用的

用于放心的 API 测试。

rest-assured
10个回答
1
投票

从下面的链接下载 hamcrest jar 并将该 jar 放在项目构建路径中。

https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all/1.3

这为我解决了上述问题。


1
投票

我对 java 项目也有同样的问题,但后来我创建了一个 Maven 项目并添加了以下依赖项:

    <dependencies>
        <dependency>
          <groupId>io.rest-assured</groupId>
          <artifactId>rest-assured</artifactId>
          <version>4.3.3</version>
          <scope>test</scope>
        </dependency>`
        <dependency>
          <groupId>io.rest-assured</groupId>
          <artifactId>json-path</artifactId>
          <version>4.3.3</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>io.rest-assured</groupId>
          <artifactId>json-schema-validator</artifactId>
          <version>4.3.3</version>
          <scope>test</scope>
        </dependency>
    <dependencies>

并导入以下库:

    import io.restassured.RestAssured;
    import static io.restassured.RestAssured.*;

就这样,事情就解决了。但对于 java 项目也是如此,Rest Assured 4.3.3 jar 不起作用。


1
投票

试试这个 --> 从浏览器手动下载 jar 文件,将其放在一边并在构建路径 > 模块路径中进行配置 > 单击添加外部 jar,它将解决问题。这可能是在 maven 中添加依赖项的限制


0
投票

首先确保您已完成所有推荐的静态导入

接下来,“assertThat()”需要参数。 RestAssured 提供了方便的方法,因此您实际上不需要将其用于常见断言。因此,请尝试将您的

then()
重写为:

then().
  statusCode(200).
  contentType(ContentType.JSON);

0
投票

从下面的链接下载 jar 并将其放置在项目构建路径中 https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all/1.3

这对我有用。


0
投票

您仍然面临这个问题 在构建路径 -> modulerpath 中添加此 Jar 添加这个罐子 https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all/1.3 问题将会得到解决。


0
投票

仅从 pom.xml 中删除 Hamcrest 的所有依赖项即可为我解决此问题。


0
投票

从下面的依赖关系中删除行 - 测试...它限制了范围。

<!-- 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>

-1
投票

打开 pom.xml 文件并从所有依赖项中删除测试行。这为我解决了上述问题。


-1
投票

打开 pom.xml 文件并从所有依赖项中删除测试行。这为我解决了上述问题。

© www.soinside.com 2019 - 2024. All rights reserved.