为每次测试运行提供隔离邮箱
QA 与邮件测试自动化
为每个测试创建唯一的邮箱地址。验证注册流程、密码重置和事务性邮件,避免共享邮箱的污染问题。通过 Polling API 轻松集成 CI/CD 管道,测试后自动清理。
核心功能
- 每个测试用例使用唯一地址
- 轮询 API 便于 CI/CD 集成
- 对邮件内容进行断言
- 测试后自动清理
示例
# RSpec example
describe "User signup flow" do
it "sends verification email" do
# Create unique inbox for this test
inbox = Mailhook.create_random_address
# Trigger signup in your app
user = create(:user, email: inbox.address)
UserMailer.verification(user).deliver_now
# Assert email was received
emails = Mailhook.poll_inbox(inbox.id)
expect(emails.count).to eq(1)
expect(emails.first.subject).to include("Verify")
# Extract verification link
link = emails.first.text_body.match(/https?:\/\/\S+/)[0]
expect(link).to include("/verify")
end
end