How to make a new testset type

I want to make a new testset type such that doing

@testset MyTest "integer addition" begin
    @test 1 + 1 == 2
end

inserts the statement println("- "^40) both before and after printing the results of the @test (those cool Test summaries).

How do I do it? The documentation on Unit testing is a bit sparse around this point. It says is that it is possible to define a custom test set, subtype of AbstractTestSet.

EDIT: In addition to the above, would be nice to have a way to do t = time() at the start of the test and elapsed = time() - t at the end, to print time taken. I also have no clue how to do this (using custom testsets of course).

Apparently I missed that this page exists: Unit Testing · The Julia Language !

I will use it to try and answer my own question!

1 Like

I got no idea how could this be done with a custom testset, as the interface is extremely complicated for my taste. I don’t even know if what I want to do is possible.

My solution is my own custom function:

function separator()
    println("\n")
    println("- "^40)
    println("\n")
end

"""
    custom_testset(description, f, args...)
Wrap a testset around `f(args...)` which times the result
and separates the test from others (`println`).
"""
function custom_testset(description, f, args...)
    t = time()
    @testset "$(d)" begin
        f(args...)
    end
    println("Required time: $(round(time()-t, digits=3)) sec.")
    separator()
end