Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing Guidelines

Guidelines for writing tests in Bindy.

Test Structure

#![allow(unused)]
fn main() {
#[cfg(test)]
mod tests {
    use super::*;
    
    #[test]
    fn test_name() {
        // Arrange
        let input = create_input();
        
        // Act
        let result = function_under_test(input);
        
        // Assert
        assert_eq!(result, expected);
    }
}
}

Unit Tests

Test individual functions:

#![allow(unused)]
fn main() {
#[test]
fn test_build_configmap() {
    let instance = create_test_instance();
    let configmap = build_configmap(&instance);
    
    assert_eq!(configmap.metadata.name, Some("test".to_string()));
}
}

Integration Tests

Test with Kubernetes:

#![allow(unused)]
fn main() {
#[tokio::test]
#[ignore]  // Requires cluster
async fn test_full_reconciliation() {
    let client = Client::try_default().await.unwrap();
    // Test logic
}
}

Test Coverage

Aim for >80% coverage on new code.

CI Tests

All tests run on:

  • Pull requests
  • Main branch commits