海蜇鱼 0.0.4

海蜇鱼 0.0.4

杨耀宏维护。



海蜇鱼 0.0.4

海蜇鱼

pipeline status coverage report

这是什么?

海蜇鱼是一个库,可以解析.api文件并根据文件内容模拟所有网络请求。

待办事项

  • 读取.api文件并模拟请求
  • 自定义匹配处理程序
  • 提供匹配JSON模式的选择

愿景

在测试环境中,Jellyfish应作为应用的API端点。

UI 测试单元测试不需要使用此框架模拟网络请求。

在生产环境中,我们只需移除Jellyfish,应用应向生产服务器发送请求并正常运行。

依赖项

用法

使用.apib文件启动stub

import Jellyfish

var jellyfish: Jellyfish = Jellyfish()

jellyfish.stub(docPath: Bundle.main.path(forResource: "testing_normal_blueprint", ofType: "apib")!)

停止stub

jellyfish.stop()

使用URLSessionConfiguration时,需要调用.jellyfishConfiguration

例如,与Alamofire一起使用时

import Alamofire
        
sessionManager = Alamofire.SessionManager(configuration: .jellyfishConfiguration)

sessionManager.request("https://example.com/message").responseString { result in
    print("==================Alamofire")
    print(result.description)
}

您可以使用addMatcher(to:)覆盖默认匹配器函数

jellyfish.addMatcher(to: "/message") { req in
  let str: String = "This is a message"
  return APIResponse(headers: ["Server": "Custom Handler"], responseCode: 200, body: str.data(using: .utf8)!)
}