npx skills add ...
npx skills add langchain-ai/skills-benchmarks --skill testing-patterns
npx skills add langchain-ai/skills-benchmarks --skill testing-patterns
Unit testing and integration testing best practices
Write effective, maintainable tests using modern patterns.
from unittest.mock import Mock, patch
@patch('services.email.send_email')
def test_sends_welcome_email(mock_send):
mock_send.return_value = True
register_user({"email": "test@example.com"})
mock_send.assert_called_once_with(
to="test@example.com",
template="welcome"
)import pytest
from factories import UserFactory
@pytest.fixture
def user():
return UserFactory.create(role="admin")
@pytest.fixture
def authenticated_client(user):
client = TestClient(app)
client.login(user)
return client
def test_admin_dashboard(authenticated_client):
response = authenticated_client.get("/admin")
assert response.status_code == 200@pytest.mark.integration
def test_full_checkout_flow(db_session, stripe_mock):
# Create test data
user = create_user()
product = create_product(price=100)
# Execute flow
cart = add_to_cart(user, product)
order = checkout(cart, payment_method="card")
# Verify
assert order.status == "completed"
assert stripe_mock.charges.create.called