Deno.test() API and can include assertions from the standard library.
Basic Testing
Writing Your First Test
math_test.ts
Test File Naming
Deno automatically discovers test files matching these patterns:*_test.ts*_test.tsx*_test.js*_test.jsx*.test.ts*.test.tsx*.test.js*.test.jsx
Test Structure
Basic Test Format
Test with Options
Async Tests
Assertions
Deno’s standard library provides comprehensive assertion functions:Test Permissions
Specify Permissions Per Test
No Permissions Test
Test Organization
Test Steps
Organize complex tests with steps:Before and After Hooks
Filtering Tests
Run Specific Tests
Ignore Tests
Focus on Specific Tests
Test Configuration
Configure in deno.json
deno.json
Named Permission Sets
deno.json
Coverage
Generate Coverage
Coverage in CI
Sanitizers
Deno includes built-in sanitizers to catch common issues:Resource Sanitizer
Detects resource leaks (files, network connections):Operation Sanitizer
Detects pending async operations:Exit Sanitizer
DetectsDeno.exit() calls:
Reporters
Built-in Reporters
Multiple Reporters
Watch Mode
Automatically re-run tests on file changes:Parallel Testing
Tests run in parallel by default:Real-World Example
user_test.ts
Best Practices
Test naming
Use descriptive test names that explain what is being tested
One assertion per test
Keep tests focused with specific assertions
Use test steps
Organize complex tests with steps for better readability
Clean up resources
Always close files, connections, and other resources
Minimal permissions
Grant only the permissions each test needs
Enable coverage
Track code coverage to ensure thorough testing
Configuration Example
deno.json