> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usetusk.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Test Generation

> How Tusk generates tests with codebase and business context

## Overview

Tusk utilizes an optimal mix of LLM-based and rule-based techniques to generate tests that are both **comprehensive** and **context-aware**.

Our rule-based techniques like using the Language Server Protocol and abstract syntax tree enable Tusk to find relevant codebase context 3x faster than similar tools while being more reliable.

Unlike general-purpose AI copilots or chatbots, Tusk generates tests with targeted knowledge of your mature codebase and business logic and **autonomously runs and iterates** on the tests to ensure they are valid. Additionally, our agent uses secondary filters to make sure that tests are de-duplicated and of high relevance to the PR/MR.

These built-in mechanisms abstract away the overhead of manually writing good tests.

## Generating High Quality Tests

We've designed Tusk's test generation pipeline to replicate the process of a senior software engineer writing tests by hand, while taking into account the nuances of working with LLMs.

Here's a high-level rundown of Tusk's test generation pipeline:

```mermaid theme={null}
flowchart TD
    subgraph initial_input
        subgraph business_context
            B[PR/MR description]
            C[Jira/Linear ticket description]
        end
        subgraph codebase_context
            D[PR/MR diff]
            E[Definitions of symbols modified]
            F[Usage of symbols modified]
            G[Stack trace for modified symbols]
        end
    end
    subgraph testing_guidelines
        H[Existing relevant unit tests]
        I[Existing relevant mocks]
        J[User-defined test generation instructions]
    end
    
    A[PR/MR is raised] --> initial_input
    initial_input --> testing_guidelines

    K[Happy path and edge case scenarios]
    testing_guidelines --> K
    L[Generate test code]
    K --> L
    M[Run test in ephemeral sandbox]
    L --> M

    N{Error when running test?}
    M --> N
    O[Fix test code based on error logs]
    P[Add test case to list of tests]
    Q[Filter to most relevant tests]
    R[Show tests in GitHub or Tusk UI]
    S{Existing test file?}
    T[Update existing test file]
    U[Create new test file]
    V[Tests committed to PR/MR's branch]

    N --> |No| P
    N --> |Yes| O
    O --> M
    P --> Q
    Q --> R
    R --> |User incorporates tests| S
    S --> |Yes| T
    S --> |No| U
    T --> V
    U --> V
```
