Skip to main content

Testing

This guide covers testing practices, test structure, and how to write effective tests for SGLang.

Test Structure

SGLang tests are organized in the test/ directory:

Running Tests

Run All Tests

Run Specific Tests

Run Tests in Parallel

Writing Tests

Basic Test Structure

Testing with HTTP Server

Testing Async Code

Test Utilities

Reusable Fixtures

Create shared fixtures in test/test_utils.py:
Use in tests:

Assertions

Performance Testing

Throughput Test

Latency Test

Integration Testing

End-to-End Test

Accuracy Testing

GSM8K Test

Mocking and Fixtures

Mock External Dependencies

Test Best Practices

Keep Tests Fast

  • Reuse server instances across tests (use setUpClass)
  • Use small models for testing (e.g., Llama-3.2-1B)
  • Set short max_new_tokens for speed
  • Split long test files into multiple files

Make Tests Deterministic

Test Error Handling

Use Descriptive Test Names

Document Tests

CI Integration

GitHub Actions

Tests run automatically in CI. See workflow configuration in .github/workflows/.

Skipping Slow Tests

Debugging Tests

Run Single Test with Verbose Output

Use Python Debugger

Common Patterns

Parameterized Tests

Temporary Files

Resources

Next Steps