BranchTests.jl simplifies testing complex state. The package offers a single @testbranch
macro - an alternative to the @testset
. The difference shows when you nest the “test branches” defined with @testbranch
. Every path from the root to a leaf @testbranch
defines a test independent from every other test.
Here’s a single motivating example from the Github README - a test which has a single failing branch:
@testbranch "Vector" begin
v = Vector{Int}()
@test isempty(v)
@testbranch "adds one element" begin
push!(v, 1)
@test length(v) == 1
@testbranch "adds another element" begin
push!(v, 2)
@test length(v) == 1 # FAIL: should be 2
end
@testbranch "removes element" begin
pop!(v)
@test isempty(v)
end
end
end
Result:
adds another element: Test Failed at REPL[4]:11
Expression: length(v) == 1
Evaluated: 2 == 1
Stacktrace:
[1] macro expansion at ./REPL[4]:11 [inlined]
[2] macro expansion at /projects/BranchTests.jl/src/BranchTests.jl:229 [inlined]
...
[12] (::var"#75#76")(::BranchTests.Run) at /projects/BranchTests.jl/src/BranchTests.jl:228
Test Summary: | Pass Fail Total
Branches - Vector(2) | 5 1 6
Vector | 2 1 3
adds one element | 1 1 2
adds another element | 1 1
Vector | 3 3
ERROR: Some tests did not pass: 5 passed, 1 failed, 0 errored, 0 broken.
Hope you find this useful. I certainly do.
There’s more information in the README on the linked Github repo.