# Package testing; setup and teardown

**URL:** <https://discourse.julialang.org/t/package-testing-setup-and-teardown/102834>\
**Category:** New to Julia\
**Tags:** testing\
**Created:** [August 15, 2023, 3:35pm UTC](https://discourse.julialang.org/t/package-testing-setup-and-teardown/102834 "2023-08-15T15:35:35Z")\
**Posts on this page:** 2\
**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 15, 2023, 3:35pm UTC](https://discourse.julialang.org/t/package-testing-setup-and-teardown/102834/1 "2023-08-15T15:35:35Z")

</div>

I have a package that wraps a vendor library. There is one main object that is exposed (a simulator) and the changeable parts are all available by performing functions on the main object, made to look C++ ish with `getproperty`.

I’d like to have some testing workflow like this:

```julia
m = MainApp()
m.Init("simulator_setup.ini")

v = m.GetViewer()
# ... test the viewer

m = nothing # set the main thing up for garbage collection

# now start on next thing
m = MainApp()
m.Init("different_setup.ini")

b = m.SomeOtherSubsystem()
# ... test the subsystem
# ... etc., etc

```

I have seen a suggestion here that recommends using [do blocks](https://discourse.julialang.org/t/setup-and-teardown-in-test-module/68589/4). I can see how that would get me test setup, but I can’t see how that would get me test _teardown_. What I was hoping for was something like [dynamic-wind](https://docs.racket-lang.org/reference/cont.html#%28def._%28%28quote._~23~25kernel%29._dynamic-wind%29%29) in Racket … i.e., setup runs, my test runs, then teardown runs.

Perhaps this is already possible and easy in Julia, but I just haven’t figured it out yet?

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [August 15, 2023, 3:52pm UTC](https://discourse.julialang.org/t/package-testing-setup-and-teardown/102834/2 "2023-08-15T15:52:06Z")

</div>

I didn’t really get what your question is. The thread you linked seems to demonstrate the use of `do` blocks quite nicely and your code example could be rephrased rather easily like so

```julia
function mytest(testcode, setupfile)
    m = MainApp()
    m.Init(setupfile)
    try
        testcode(m)
    finally
        # do cleanup
        # not cleanup present in your example
    end
end

mytest("simulator_setup.ini") do m
    v = m.GetViewer()
    # ... test the viewer
end

mytest("different_setup.ini") do m
    b = m.SomeOtherSubsystem()
    # ... test the subsystem
end

```

`dynamic-wind` gives quite different features which aren’t needed in Julia due to the lack of continuations (I think, I am not an expert with continuations or Racket).
