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

Important: If you're encountering any problem declaring contracts, please read the Blake Hash Support information.

Tests Partitioning

When your test suite contains a large number of tests (especially fuzz tests), it can be helpful to split them into partitions and run each partition separately, for example in parallel CI jobs.

snforge supports this via the --partition <INDEX>/<TOTAL> flag.

When this flag is provided, snforge will divide all collected tests into TOTAL partitions and run only the partition with the given INDEX (1-based).

Example

Let's consider package a with the following 7 tests:

#[test]
fn test_a() {
    assert_eq!(1 + 1, 2);
}

#[test]
fn test_b() {
    assert_eq!(1 + 1, 2);
}

#[test]
fn test_c() {
    assert_eq!(1 + 1, 2);
}

#[test]
fn test_d() {
    assert_eq!(1 + 1, 2);
}

#[test]
fn test_e() {
    assert_eq!(1 + 1, 2);
}

#[test]
fn test_f() {
    assert_eq!(1 + 1, 2);
}

#[test]
fn test_g() {
    assert_eq!(1 + 1, 2);
}

Running snforge test --partition 1/2 will run tests test_a, test_c, test_e, test_g (4 tests), while running snforge test --partition 2/2 will run tests test_b, test_d, test_f (3 tests).

$ snforge test --partition 1/2
Output:

Running partition run: 1/2

Collected 4 test(s) from tests_partitioning package
Running 4 test(s) from tests/
[PASS] tests_partitioning_integrationtest::example::test_a ([..])
[PASS] tests_partitioning_integrationtest::example::test_e ([..])
[PASS] tests_partitioning_integrationtest::example::test_c ([..])
[PASS] tests_partitioning_integrationtest::example::test_g ([..])
Running 0 test(s) from src/
Tests: 4 passed, 0 failed, 0 ignored, 0 filtered out

Finished partition run: 1/2, included 4 out of total 7 tests

See example GitHub Actions workflow demonstrating partitioned test execution here.