~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Types of Tests and Testable Types

Use left/right arrows or swipe to navigate backwards/forwards

github.com/swoogles/TTTT

Why talk about this stuff?

Non-Objectives

Objectives

Types of Tests

Unit Tests

Unit Tests

Unit Tests

Boundary Tests

Boundary Tests

Boundary Tests

Integration Tests - Internal

Integration Tests - Internal

Integration Tests

End-to-End Tests

End-to-End Tests

End-to-End Tests

Selenium Tests

Selenium Tests

Selenium Tests

Integration Tests - External

Integration Tests - External

Integration Tests

Code Coverage

How should we achieve full coverage?

Code Coverage

Code Coverage

Code Coverage

Code Coverage

Code Coverage

Code Coverage

Code Coverage

Code Coverage

Code Coverage

Code Coverage

Code Coverage

Code Coverage

Code Coverage

| Test Type | Coverage | | ——- | ——– | | Unit | Additive | | Integration | Combinatorial | | End-to-End | max(Combinatorial) | | Boundary | Additive |

Live Demo

Demo Concepts

class ServiceStatus {
    void ensureServiceIsRunning(String name) {
        // Check property file and throw a RuntimeException 
        // if turned off.
    }
}

Demo Concepts

abstract class UnreliableService {
    private List<UnreliableService> dependencies;
    
    Duration fallibleAction() {
        ServiceStatus.ensureServiceIsRunning(serviceName);
        this.dependencies.forEach(
            dependency->dependency.fallibleAction
        );
        ...
    }
}

Demo Concepts

UnreliableService Implementations

Demo Concepts

Live Demo

Get thee to Intellij

Time-Sensitive Tests

Concepts that can be painful to model:

“Tomorrow”

“Last year”

“In the next 6 months”

Time-Sensitive Tests

We want tests that:

Time-Sensitive Tests

    void test() {
        List<Event> lastTen =
            eventLogic.inLast10Minutes(Instant.now());
        // Other commands...
        List<Event> lastOne = 
            eventLogic.inLastMinute(Instant.now());
            
        assertTrue( lastTen.containsAll(lastOne) );
    }

Entire Test runs at the current Instant

    void test() {
        Instant now = Instant.now();
        
        List<Event> lastTen = eventLogic.inLast10Minutes(now);
        // ... Other commands/assertions ...
        List<Event> lastOne = eventLogic.inLastMinute(now);
        
        assertTrue( lastTen.containsAll(lastOne) );
    }

Entire Test runs at a fixed Instant

    Clock clock = Clock.fixed(
                    Instant.parse("2018-08-08T00:00:00Z"),
                    ZoneId.systemDefault());
    void test() {
        Instant now = clock.instant();
        
        List<Event> lastTen = eventLogic.inLast10Minutes(now);
        // Other commands ...
        List<Event> lastOne = eventLogic.inLastMinute(now);
        
        assertTrue( lastTen.containsAll(lastOne) );
    }

Completely Time-Insensitive Test

    Clock clock = Clock.fixed(
                    Instant.parse("2018-08-08T00:00:00Z"),
                    ZoneId.of("America/Denver"));
    void test() {
        Instant now = clock.instant();
        
        List<Event> lastTen = eventLogic.inLast10Minutes(now);
        // Other commands ... 
        List<Event> lastOne = eventLogic.inLastMinute(now);
        
        assertTrue( lastTen.containsAll(lastOne) );
    }

Solo Project Stats

codebase instances runtime
adolescent Mocks 0:00:01
adolescent Real 0:00:04
established Mocks 0:00:10
established Real 0:00:25
mature Mocks 0:00:19
mature Real 0:00:59

Mid-sized Organization Stats

codebase instances runtime
adolescent Mocks 0:00:49
adolescent Real 0:02:03
established Mocks 0:04:49
established Real 0:12:00
mature Mocks 0:09:16
mature Real 0:27:53

Questions

Have any?