1

我通过记录服务器的事务创建了我的映射。现在我想使用我的 json 映射文件来加载映射。为此,我有以下代码:

import com.github.tomakehurst.wiremock.WireMockServer;

public class mockedTests{
    public static WireMockServer mockingServer;
    
    public void loadMaps(){
        mockingServer.loadMappingsUsing(****);
    }
}

我检查了wiremock代码,该loadMappingsUsing方法需要aMappingsLoader作为其参数。但是,我找不到MappingsLoader正确创建的方法。我在文档中找不到任何内容,也找不到任何在线示例或教程。此外,我坚持使用WireMockServer对象而不是规则或WireMock对象。有谁知道我如何创建一个MappingsLoader来加载我的映射 json 文件?我正在使用独立版本的wiremock。谢谢。

4

1 回答 1

2

默认情况下,WireMock 会在/src/test/resources. 如果您在 Java 中创建 WireMock 实例并将文件放在自定义位置,则需要传入一个option()对象,.usingFilesUnderDirectory("/path/to/files-and-mappings-root")并附上

WireMockServer wm = new WireMockServer(options().usingFilesUnderDirectory("/path/to/files-and-mappings-root"))

如果您需要在从命令行启动 WireMock 时执行此操作,则类似于:

$ java -jar wiremock-standalone-2.27.0.jar --root-dir "/path/to/files-and-mappings-root"

我认为您最初的问题可能来自未使用options()对象启动 WireMock 服务器或规则。

于 2020-07-22T13:13:16.747 回答