iOS Unit Tests
barK automatically detects XCTest environments and switches to console output โ no configuration required.
How Test Detection Works
barK inspects the loaded frameworks at runtime for XCTest. When detected, ColoredUnitTestTrainer activates automatically and NSLogTrainer output is suppressed.
This works for:
- XCTest unit tests (via
xctestrunner) - Xcode UI tests
- CI runs (GitHub Actions, Fastlane, etc.)
Recommended Test Setup
import XCTest
@testable import shared
final class ExampleTests: XCTestCase {
override func setUp() {
super.setUp()
Bark.releaseAllTrainers()
Bark.train(trainer: ColoredUnitTestTrainer())
}
override func tearDown() {
Bark.releaseAllTrainers()
super.tearDown()
}
func testSomething() {
Bark.d("Starting test")
// ...
Bark.i("Test completed")
}
}
Choosing a Test Trainer
ColoredUnitTestTrainer
ANSI-colored output. Works in Terminal and CI (GitHub Actions, Fastlane). Falls back to plain text automatically in Xcode's test console, which doesn't support ANSI.
UnitTestTrainer
Plain text with timestamps. Always readable regardless of environment โ safe choice for Xcode console:
Xcode console limitation
Xcode's test output panel strips ANSI escape codes. If you're running tests exclusively in Xcode (not from the command line), UnitTestTrainer gives cleaner output.
Color Support Detection
ColoredUnitTestTrainer auto-detects ANSI support using two checks:
isatty()โ is stdout connected to a terminal?TERMenvironment variable โ is it set to a color-supporting value?
| Environment | Colors |
|---|---|
| Terminal (macOS) | โ |
| GitHub Actions | โ |
| Fastlane | โ |
| Xcode test console | โ (falls back to plain text) |
Log Level Filtering in Tests
override func setUp() {
super.setUp()
Bark.releaseAllTrainers()
// Only show warnings and above during this test class
Bark.train(trainer: ColoredUnitTestTrainer(minLevel: .warning))
}
Running Tests from the Command Line
barK's Kotlin tests on iOS run via Gradle:
Colors will render correctly in terminal output. Xcode tests can also be run directly: