Test environment nhyehyɛeɛ
Anammɔn a edi kan de email verification tests yɛ automatic no ne sɛ wobɛhyehyɛ test environment pa. Nea wohia: API key, test framework (sɛ pytest anaa Jest), ne ɔkwan a wubɛfa so akɔ wo CI/CD system mu. Wo test environment no ne wo production environment no nsɛ.
API dwumadi
EvilMail API so no, wubɛtumi de program ayɛ email addresses foforɔ. Nea edi kan fa wo API key, afei send request te sɛ eyi:
curl -X POST https://api.evilmail.com/v1/inboxes
-H "Authorization: Bearer YOUR_API_KEY"
-H "Content-Type: application/json"Eyi bɛma wo throwaway email address a ɛyɛ soronko.
Inbox hwɛhwɛ
Sɛ wɔde email no kɔ wie a, fa polling mechanism hwɛ inbox no. Send requests kɔ API no bere biara mu na hwɛ sɛ message foforɔ aba anaa.
curl https://api.evilmail.com/v1/inboxes/{inbox_id}/messages
-H "Authorization: Bearer YOUR_API_KEY"Python nhwɛsoɔ
Python nhwɛsoɔ a ɛwɔ aseɛ ha yi kyerɛ verification test flow mu nyinaa:
import requests
import time
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.evilmail.com/v1"
def create_inbox():
resp = requests.post(f"{BASE_URL}/inboxes",
headers={"Authorization": f"Bearer {API_KEY}"})
return resp.json()
def poll_inbox(inbox_id, timeout=30):
start = time.time()
while time.time() - start < timeout:
resp = requests.get(f"{BASE_URL}/inboxes/{inbox_id}/messages",
headers={"Authorization": f"Bearer {API_KEY}"})
messages = resp.json()
if messages:
return messages[0]
time.sleep(2)
raise TimeoutError("No message received")
def test_email_verification():
inbox = create_inbox()
trigger_verification(inbox["email"])
message = poll_inbox(inbox["id"])
assert "verify" in message["subject"].lower()
assert message["body"] is not NoneCI/CD mu bɛhyɛ
Sɛ wopɛ sɛ wode wo tests hyɛ CI/CD pipeline mu a, kora wo API key sɛ environment variable na fa ka test step no ho. Wubɛtumi de ka GitHub Actions, GitLab CI, anaa Jenkins ho a ɛnyɛ den.
Assertions akyerɛw
Ma tests a ɛyɛ adwuma yie no, hwɛ nneɛma yi: sɛ email no bae wɔ bere a ɛsɛ mu, sɛ subject line no yɛ pɛ, sɛ verification link no wɔ hɔ, ne sɛ link no yɛ adwuma. Saa assertions yi ma wuhu sɛ verification flow no nyinaa yɛ adwuma yie.
Tests trɛtrɛ mu
Sɛ wopɛ sɛ wo tests kɔ bere koro mu a, yɛ inbox foforɔ ma test biara. Hwɛ API rate limits no yie na fa delays a ɛfata ka ho ma test groups akɛseɛ.

