Instruct Julia to skip unit testing?

Hi Niceno! Typically all of the @test and @testset macros are found within runtests.jl (and any included 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, 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)

module MyPackage

using InlineTest

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

end
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!

4 Likes