# \[ANN\] BranchTests.jl - simplify complex state tests

**URL:** <https://discourse.julialang.org/t/ann-branchtests-jl-simplify-complex-state-tests/59470>\
**Category:** Package Announcements\
**Tags:** package, announcement, testing\
**Created:** [April 17, 2021, 10:09am UTC](https://discourse.julialang.org/t/ann-branchtests-jl-simplify-complex-state-tests/59470 "2021-04-17T10:09:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dm3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dm3/32/2755_2.png) [@dm3](https://discourse.julialang.org/u/dm3)\
**Post date:** [April 17, 2021, 10:09am UTC](https://discourse.julialang.org/t/ann-branchtests-jl-simplify-complex-state-tests/59470/1 "2021-04-17T10:09:36Z")

</div>

[BranchTests.jl](https://github.com/dm3/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](https://github.com/dm3/BranchTests.jl) - a test which has a single failing branch:

```julia
@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:

```julia
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.
