# Instruct Julia to skip unit testing?

**URL:** <https://discourse.julialang.org/t/instruct-julia-to-skip-unit-testing/69354>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [October 7, 2021, 9:03am UTC](https://discourse.julialang.org/t/instruct-julia-to-skip-unit-testing/69354 "2021-10-07T09:03:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niceno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niceno/32/29648_2.png) [@Niceno](https://discourse.julialang.org/u/Niceno)\
**Post date:** [October 7, 2021, 9:03am UTC](https://discourse.julialang.org/t/instruct-julia-to-skip-unit-testing/69354/1 "2021-10-07T09:03:04Z")

</div>

Hi everyone,

I am new to Julia and few days ago had a moment of delight when I learned that Test package offers a very neat way to include unit testing in your code 🙂 Since then, I was putting `@testset` and `@test` wherever I though useful in my code for computational fluid dynamic simulations (which I am translating from my old Fortran code).

Once all the tests were in place, and were passing, I decided to run a simulation. To my disappointment, the parts of the code enclosed in `@testset begin ... end` constructs are still being executed when I run productive simulations. I don’t want that, when I test everything I want to simulate and used CPU to crunch numbers, not to test what was tested already.

I wonder if there is a global way to instruct Julia to skip unit testings when performing productive runs?

```
Cheers

```

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 7, 2021, 9:19am UTC](https://discourse.julialang.org/t/instruct-julia-to-skip-unit-testing/69354/2 "2021-10-07T09:19:57Z")

</div>

Welcome!

In Julia, tests are placed in a specific file in a specific place and are run only when explicitly testing a package.

Take a look at the `Example` package to see what that file and location look like: [https://github.com/JuliaLang/Example.jl/tree/master/test](https://github.com/JuliaLang/Example.jl/tree/master/test)

and of course, there’s tons of info in the docs: [Unit Testing · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Test/)

---

<div class="post-metadata">

**Author:** ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Post date:** [October 7, 2021, 10:07am UTC](https://discourse.julialang.org/t/instruct-julia-to-skip-unit-testing/69354/3 "2021-10-07T10:07:35Z")

</div>

If you want to test some conditions at runtime, you can use the `@assert` macro.

Unit testing is best done in a file located at yourproject/test/runtests.jl. That way you can use `Pkg.test()` to run the test script in runtests.jl (often this will be a file with `include` statements of other test files in the test directory).

---

<div class="post-metadata">

**Author:** ![Niceno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niceno/32/29648_2.png) [@Niceno](https://discourse.julialang.org/u/Niceno)\
**Post date:** [October 7, 2021, 10:07am UTC](https://discourse.julialang.org/t/instruct-julia-to-skip-unit-testing/69354/4 "2021-10-07T10:07:40Z")

</div>

Thanks.

---

<div class="post-metadata">

**Author:** ![Niceno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niceno/32/29648_2.png) [@Niceno](https://discourse.julialang.org/u/Niceno)\
**Post date:** [October 7, 2021, 10:11am UTC](https://discourse.julialang.org/t/instruct-julia-to-skip-unit-testing/69354/5 "2021-10-07T10:11:21Z")

</div>

Thanks Henri. I did put all the tests in the file `runtests.jl.` It is just so that this file calls all the other functions I wrote for productive runs, which do have embedded `@testset` constructs.

---

<div class="post-metadata">

**Author:** ![mmiller](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmiller/32/20805_2.png) [@mmiller](https://discourse.julialang.org/u/mmiller)\
**Post date:** [October 7, 2021, 10:42am UTC](https://discourse.julialang.org/t/instruct-julia-to-skip-unit-testing/69354/6 "2021-10-07T10:42:16Z")

</div>

Hi Niceno! Typically all of the `@test` and `@testset` macros are found within `runtests.jl` (and any `include`d files), and the functions within the package do not contain the macros. This means the tests only run when doing `Pkg.test` and not when the individual functions are run.

You can, however, use [`ReTest`](https://github.com/JuliaTesting/ReTest.jl), which uses `InlineTest`, to define tests in the same files as the code (rather than runtests.jl), and they are not run when normal functions execute.

See this example (similar to the one from the `ReTest` docs)

```nohighlight
module MyPackage

using InlineTest

function greet()
    @testset "1" begin
        @info "Testing ..."
        @test true
    end
    "Hello World"
end

end

```

```nohighlight
ulia> using ReTest, MyPackage

julia> MyPackage.greet()
"Hello World"

julia> MyPackage.runtests()
[ Info: Testing ...
      Pass  
1 | 1  

```

Disclaimer: I haven’t used `ReTest` that much, so check out the Caveats section of the docs and have a play around!

---

<div class="post-metadata">

**Author:** ![Niceno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niceno/32/29648_2.png) [@Niceno](https://discourse.julialang.org/u/Niceno)\
**Post date:** [October 7, 2021, 10:50am UTC](https://discourse.julialang.org/t/instruct-julia-to-skip-unit-testing/69354/7 "2021-10-07T10:50:19Z")

</div>

Wow man - this look marvelous, exactly what I needed 🙂

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [January 15, 2024, 3:07pm UTC](https://discourse.julialang.org/t/instruct-julia-to-skip-unit-testing/69354/8 "2024-01-15T15:07:33Z")

</div>

If you come to this issue like me some years later, it is good to know that there is also  
[TestItemRunner.jl](https://github.com/julia-vscode/TestItemRunner.jl) from the Julia-VSCode team (which also works without VSCode 😉 )

It is very similar to ReTest
