# Setting up a structure for a sequence of tests?

**URL:** <https://discourse.julialang.org/t/setting-up-a-structure-for-a-sequence-of-tests/102451>\
**Category:** New to Julia\
**Created:** [August 3, 2023, 3:22pm UTC](https://discourse.julialang.org/t/setting-up-a-structure-for-a-sequence-of-tests/102451 "2023-08-03T15:22:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [August 3, 2023, 3:22pm UTC](https://discourse.julialang.org/t/setting-up-a-structure-for-a-sequence-of-tests/102451/1 "2023-08-03T15:22:20Z")

</div>

EDIT: my issue was unrelated to the question - the problem wound up being improper spacing.

I have a package that I’d like to have some tests built in for. There is a structure that wraps some functionality in a C++ library, so I have overloaded `getproperty` for it, so it looks a bit un-Julian.

```julia
mutable struct Thing
    p::Ptr{Cvoid}
end

function Base.getproperty(this::Thing, s::Symbol)
    if s == :Foo
        function foo()
            # ... does stuff with pointer
        end
    else
        getfield(this, s)
    end
end

```

Anyhow, I want to start off my test with a setup call, and then run a sequence of tests, but this doesn’t work:

```julia
using Test

a = Thing()

@testset "Ensure Foo-ness" begin
    @test a.Foo()
    # ...
end

```

```julia
ERROR: LoadError: syntax: "begin" at /home/frylock/opt/Wrapper/test/runtests.jl:5 expected "end", got "a"

```

What is the right way to handle setup/teardown?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [August 3, 2023, 3:37pm UTC](https://discourse.julialang.org/t/setting-up-a-structure-for-a-sequence-of-tests/102451/2 "2023-08-03T15:37:40Z")

</div>

Can’t reproduce.

```julia
julia> using Test

julia> mutable struct Thing
           p::Ptr{Cvoid}
       end

julia> function Base.getproperty(this::Thing, s::Symbol)
           if s == :Foo
               function foo()
                   return true
               end
           else
               getfield(this, s)
           end
       end

julia> a = Thing(C_NULL)
Thing(Ptr{Nothing} @0x0000000000000000)

julia> @testset "Ensure Foo-ness" begin
           @test a.Foo()
       end;
Test Summary: | Pass Total Time
Ensure Foo-ness | 1 1 0.0s

```

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [August 3, 2023, 3:40pm UTC](https://discourse.julialang.org/t/setting-up-a-structure-for-a-sequence-of-tests/102451/3 "2023-08-03T15:40:36Z")

</div>

You are right sir:  
The problem was that I had a test like this:

```julia
@test_logs(:warn, "my warning") the_expression

```

instead of

```julia
@test_logs (:warn, "my warning") the_expression

```

The space was important, embarassing ☹
