mox
1,401
Stars
—
Forks
0
Watchers
—
Open Issues
待补全
许可证
Elixir
语言
—
创建时间
最近更新
项目能做什么
用于 Elixir 的 Mock 测试与显式契约定义库。
来源:AI 基于仓库事实生成
· 内容以仓库实际 README 为准
使用说明 查看原始 README 原仓库文档
中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
# Mox
[](https://hex.pm/packages/mox)
[](https://hexdocs.pm/mox)
[](https://github.com/dashbitco/mox/actions/workflows/ci.yml)
[](https://coveralls.io/github/dashbitco/mox?branch=main)
Mox is a library for defining concurrent mocks in Elixir.
The library follows the principles outlined in ["Mocks and explicit contracts"](https://dashbit.co/blog/mocks-and-explicit-contracts), summarized below:
1. No ad-hoc mocks. You can only create mocks based on behaviours
2. No dynamic generation of modules during tests. Mocks are preferably defined in your `test_helper.exs` or in a `setup_all` block and not per test
3. Concurrency support. Tests using the same mock can still use `async: true`
4. Rely on pattern matching and function clauses for asserting on the
input instead of complex expectation rules
The goal behind Mox is to help you think and define the contract between the different parts of your application. In the opinion of Mox maintainers, as long as you follow those guidelines and keep your tests concurrent, any library for mocks may be used (or, in certain cases, you may not even need one).
[See the documentation](https://hexdocs.pm/mox) for more information.
## Installation
Just add `mox` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:mox, "~> 1.0", only: :test}
]
end
```
Mox should be automatically started unless the `:applications` key is set inside `def application` in your `mix.exs`. In such cases, you need to [remove the `:applications` key in favor of `:extra_applications`](https://elixir-lang.org/blog/2017/01/05/elixir-v1-4-0-released/#application-inference) or call `Application.ensure_all_started(:mox)` in your `test/test_helper.exs`.
## Basic Usage
### 1) Add behaviour, defining the contract
```elixir
# lib/weather_behaviour.ex
defmodule WeatherBehaviour do
@callback get_weather(binary()) :: {:ok, map()} | {:error, binary()}
end
```
### 2) Add implementation for the behaviour
```elixir
# lib/weather_impl.ex
defmodule WeatherImpl do
@moduledoc """
An implementation of a WeatherBehaviour
"""
@behaviour WeatherBehaviour
@impl WeatherBehaviour
def get_weather(city) when is_binary(city) do
# Here you could call an external api directly with an HTTP client or use a third
# party library that does that work for you. In this example we send a
# request using a `httpc` to get back some html, which we can process later.
:inets.start()
:ssl.start()
case :httpc.request(:get, {"https://www.google.com/search?q=weather+#{city}", []}, [], []) do
{:ok, {_, _, html_content}} -> {:ok, %{body: html_content}}
error -> {:error, "Error getting weather: #{insp
阅读完整原文
项目深度分析 AI 生成
Elixir 契约测试与自动化 Mock 生成扩展工具
| 产品构想 | 基于 Mox 和 Behaviours,开发能够从 OpenAPI/TypeSpec 或现有代码中自动生成规范 Behaviours 和 Mox 适配桩的开发者辅助 CLI 或 SaaS 服务。 |
| 核心功能 | OpenAPI 规范解析生成 Elixir Behaviours;自动生成 Mox mock 代码与默认测试 fixture;契约漂移(Contract Drift)告警检测。 |
| 目标用户 | 维护复杂外部 API 依赖的 Elixir 研发团队。 |
| 难度/周期 | 中等 · 2-3 个月 · 成本:极低(仅需基础云服务和测试环境) |
| 收费模式 | 核心开源,高级 CLI 功能或云端契约比对服务订阅(每月 $15-50/团队)。 |
| 竞争风险 | Elixir 社区整体生态偏小,细分开发工具付费意愿偏弱。 |
| 依据 | AI推测 |
微服务与外部集成沙箱系统(面向 Elixir 栈)
| 产品构想 | 针对使用 Mox 进行单元测试后难以进行端到端契约验证的问题,提供配套的 HTTP/gRPC 本地/云端沙箱 Mock 代理服务。 |
| 核心功能 | 外部 API 请求记录并自动转换为 Mox 模拟用例;多环境统一契约验证;沙箱模拟与回放服务。 |
| 目标用户 | 有强外部 API 依赖(如 Stripe、金融通道等)的 Elixir SaaS 开发企业。 |
| 难度/周期 | 高 · 3-6 个月 · 成本:服务器与网络流量开销中等 |
| 收费模式 | 按模拟请求量或项目席位收取 SaaS 订阅费。 |
| 竞争风险 | 市场上已有 generic 的 Mock 平台(如 WireMock、Mockoon),针对 Elixir 特化的壁垒不高。 |
| 依据 | 尚需验证的假设 |
Elixir 架构测试与规范咨询/培训服务
| 产品构想 | 围绕 Dashbit 倡导的显式契约(Explicit Contracts)设计哲学,提供企业代码库质量审计、测试流水线并发优化与架构重构服务。 |
| 核心功能 | 测试执行速度性能优化(利用 Mox 并发特性优化 CI 时间);代码架构契约审查;定制化测试最佳实践培训。 |
| 目标用户 | 拥有大型 Elixir 单体应用或从其他语言迁移至 Elixir 的技术团队。 |
| 难度/周期 | 低到中等 · 1-2 周启动,按项目交付 · 成本:人力时间成本为主 |
| 收费模式 | 按咨询人天或专项项目定价收费。 |
| 竞争风险 | 难以规模化,强依赖个人知名度与 Dashbit 品牌背书的竞争。 |
| 依据 | 数据支持的判断 |
AI 基于仓库公开数据分析生成,含推测成分,不构成收益承诺。
报告会保存到 个人中心
竞品与相似项目 GitHub Search 真实检索
相似项目数据正在完善中,暂不展示(避免误导)
项目优势与风险
| 技术成熟度 | 创建时间待补全,最近推送 |
| 社区活跃 | Star 1,401 / Fork 0 / Issue 0(数据支持,可自行核实) |
| 许可证 | 未检测到(需人工确认) |
| 主要风险 | 上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价 |
安装与使用
此项目未提供 Docker 镜像,安装步骤以原仓库 README 为准(涉及依赖安装与环境配置,对新手门槛较高)。