Test Filtering >0.9.6

How to Filter Tests Correctly

Dash vs Underscore Automatic Conversion :white_check_mark:

Swift test converts target names containing dashes (-) to underscores (_) in test identifiers.

**Good news **: The tooling automatically converts dashes to underscores, so you can use either format!

Example


# ✅ Both work now (dashes are automatically converted to underscores)

./tooling.sh --test Uitsmijter-AuthorizationTests

./tooling.sh --test Uitsmijter_AuthorizationTests

# Both run 17 tests from Uitsmijter_AuthorizationTests

Test Targets in This Project

Package.swift Target Name Filter Patterns (both work)
LoggerTests LoggerTests
Uitsmijter-AuthServerTests Uitsmijter-AuthServerTests or Uitsmijter_AuthServerTests

Note: Dashes are automatically converted to underscores by tooling.sh.

Why This Happens

Swift test creates test identifiers in the format:


TargetName.SuiteName/testName

When the target name contains a dash, Swift automatically converts it to an underscore:

  • Target in Package.swift: Uitsmijter-AuthorizationTests

  • Actual test identifiers: Uitsmijter_AuthorizationTests.IsClassExistsTest/classExists()

You can verify this by running:


swift test list | grep Uitsmijter

Output shows:


Uitsmijter_AuthServerTests.IsClassExistsTest/classDoNotExists()

Uitsmijter_AuthServerTests.IsClassExistsTest/classExists()

Uitsmijter_AuthServerTests.JSFunctionsHashingTest/md5()

...

Verification

Check that filtering works:


# Filter to specific target (17 tests)

./tooling.sh --test Uitsmijter_AuthorizationTests

Output should show:


Test filter: --filter Uitsmijter_AuthorizationTests

...

✔ Test run with 17 tests in 5 suites passed after X.XXX seconds.

Both formats work:


# With dash (automatically converted)

./tooling.sh --test Uitsmijter-AuthorizationTests

# With underscore (passed as-is)

./tooling.sh --test Uitsmijter_AuthorizationTests

Both produce the same output with 17 tests running.

Debug Output

The test.sh script includes debug output to show when a filter is applied:


Test filter: --filter Uitsmijter_AuthorizationTests

Or when no filter is set:


No test filter set - running all tests

Other Filter Patterns

You can also filter by suite name or individual test name:


# Filter by suite

./tooling.sh --test "Uitsmijter_AuthServerTests.IsClassExistsTest"

# Filter by specific test

./tooling.sh --test "Uitsmijter_AuthServerTests.IsClassExistsTest/classExists"

# Filter multiple targets with pattern

./tooling.sh --test "LoggerTests"