Skip to main content

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

Or using the build script:

Run Tests with Coverage

This generates a 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

This runs multiple 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

  1. Unit tests: Test individual functions and components
  2. Integration tests: Test component interactions
  3. End-to-end tests: Test complete user workflows
  4. 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

Next Steps