Skip to main content
🌟 Test like a pro! These best practices come from real-world experience testing MCP servers and agents at scale. Follow these guidelines to build a robust, maintainable test suite.

Quick best practice finder

Jump to what you need:

Test Design

Writing effective tests

Organization

Structuring test suites

Assertions

Choosing the right checks

Performance

Fast and efficient testing

Reliability

Reducing flakiness

Maintenance

Keeping tests healthy

Test design principles

1. Test one thing at a time (by default)

✅ Do: Focus each test on a single behavior or feature
When to go broader: Complex agent behaviors sometimes require end-to-end scenarios (multi-tool flows, recovery, efficiency). In those cases:
  • Keep assertions layered and named (content, tools, performance, judge)
  • Bound scope (one coherent workflow per test)
  • Use separate tests for alternative branches or failure paths
Example end-to-end scenario:

2. Use descriptive names

✅ Do: Name tests to describe what they verify
❌ Don’t: Use vague or generic names

3. Make tests independent

✅ Do: Each test should run in isolation
❌ Don’t: Depend on other tests or shared state

4. Use explicit assertions

✅ Do: Be specific about expectations
❌ Don’t: Use vague or implicit checks

Test organization

Directory structure

Organize tests by functionality and type:

Test file naming

Follow consistent naming patterns:
Use classes or modules to group related tests:

Assertion strategies

Layered assertions

Build assertions from deterministic to probabilistic:

Assertion selection guide

Choose assertions based on what you’re testing:

Custom assertion patterns

Create reusable assertion combinations:

Performance optimization

Minimize LLM calls

✅ Do: Batch operations when possible
❌ Don’t: Make unnecessary separate calls

Use appropriate models

Match model to test complexity:

Parallel execution

Run independent tests concurrently:

Cache when appropriate

Reliability patterns

Handle non-determinism

LLMs are probabilistic, so account for variation:

Reduce flakiness

Common causes and solutions:

Test isolation

Ensure tests don’t affect each other:

Maintainability

Documentation in tests

Document complex test logic:

Parameterized test patterns

Make tests reusable with parameters:

Test data management

Centralize test data:

Version your tests

Track test evolution with your code:

Anti-patterns to avoid

1. Testing implementation details

❌ Don’t: Test internal implementation
✅ Do: Test behavior and outputs

2. Overusing LLM judges

❌ Don’t: Use judges for deterministic checks
✅ Do: Use appropriate assertion types

3. Ignoring test failures

❌ Don’t: Skip or ignore failing tests
✅ Do: Fix or properly mark flaky tests

4. Magic numbers and strings

❌ Don’t: Use unexplained values
✅ Do: Use named constants with explanations

Testing checklist

Use this checklist for every test you write:
  • Single purpose - Tests one specific behavior
  • Descriptive name - Clearly indicates what’s being tested
  • Independent - Doesn’t depend on other tests
  • Deterministic - Produces consistent results
  • Fast - Runs quickly (< 5 seconds for unit tests)
  • Documented - Has docstring explaining purpose
  • Maintainable - Easy to understand and modify
  • Appropriate assertions - Uses right assertion types
  • Error handling - Handles expected failures gracefully
  • Cleanup - Cleans up any created resources

Advanced patterns

Property-based testing

Test properties rather than specific examples:

Contract testing

Define contracts between components:

Mutation testing

Verify your tests catch bugs:

Continuous improvement

Metrics to track

Monitor your test suite health:
  • Pass rate - Should be > 95% for stable tests
  • Execution time - Track trends, investigate increases
  • Flakiness - Identify and fix flaky tests
  • Coverage - Ensure critical paths are tested
  • Maintenance cost - Time spent fixing tests

Regular reviews

Schedule periodic test suite reviews:
  1. Weekly: Review failed tests, fix or mark as flaky
  2. Monthly: Remove obsolete tests, update assertions
  3. Quarterly: Refactor test organization, update patterns
  4. Yearly: Major test suite health assessment

You’re now equipped with best practices that will make your mcp-eval tests reliable, maintainable, and valuable! Remember: good tests are an investment in your project’s future. 🌟