Overview
Viction provides comprehensive testing infrastructure to ensure code quality and reliability. The testing framework includes unit tests, integration tests, and development tools.Running Tests
Run All Tests
Run Tests with Coverage
coverage.txt file with detailed coverage information:
Run Specific Package Tests
Run Individual Test
Test Configuration
Test Flags
Viction’s test suite supports various flags:-p 1: Run tests sequentially (used in CI for slow builders)-covermode=atomic: Thread-safe coverage mode-cover: Enable coverage collection-coverprofile=file: Write coverage profile to file-timeout: Set test timeout (default varies by test)-race: Enable race detector-short: Run shorter version of tests
Example Test Commands
Writing Tests
Unit Test Example
Benchmark Tests
Table-Driven Tests
Integration Testing
Testing with Local Node
RPC Testing
Smart Contract Testing
Using Go Bindings
JavaScript Contract Testing (Hardhat)
Run Hardhat Tests
Code Quality Tools
Run Linters
- vet: Examines Go source code and reports suspicious constructs
- gofmt: Checks code formatting
- misspell: Finds commonly misspelled English words
- goconst: Finds repeated strings that could be constants
- unconvert: Removes unnecessary type conversions
- gosimple: Simplifies code
Format Code
Static Analysis
Development Workflow
Local Development Node
Testing Against Local Node
Continuous Integration
GitHub Actions Example
Performance Testing
Load Testing RPC Endpoints
Benchmark Node Performance
Debugging
Enable Debug Logging
Debug RPC Calls
Transaction Tracing
Best Practices
Test Organization
- Unit tests: Test individual functions and components
- Integration tests: Test component interactions
- End-to-end tests: Test complete user workflows
- Benchmark tests: Measure performance
Test Coverage Goals
- Aim for >80% code coverage
- Focus on critical paths
- Test edge cases and error conditions
- Test concurrent scenarios
CI/CD Guidelines
- Run tests on every commit
- Require passing tests for merges
- Generate and track coverage reports
- Run linters and formatters
- Automate deployment to testnets