# How to make a new testset type

**URL:** <https://discourse.julialang.org/t/how-to-make-a-new-testset-type/15463>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 25, 2018, 12:05pm UTC](https://discourse.julialang.org/t/how-to-make-a-new-testset-type/15463 "2018-09-25T12:05:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [September 25, 2018, 12:05pm UTC](https://discourse.julialang.org/t/how-to-make-a-new-testset-type/15463/1 "2018-09-25T12:05:20Z")

</div>

I want to make a new testset type such that doing

```julia
@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](https://docs.julialang.org/en/v1/stdlib/Test/#Working-with-Test-Sets-1) 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).

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [September 25, 2018, 12:14pm UTC](https://discourse.julialang.org/t/how-to-make-a-new-testset-type/15463/2 "2018-09-25T12:14:21Z")

</div>

Apparently I missed that this page exists: [Unit Testing · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Test/#Creating-Custom-AbstractTestSet-Types-1) !

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

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [September 25, 2018, 12:58pm UTC](https://discourse.julialang.org/t/how-to-make-a-new-testset-type/15463/3 "2018-09-25T12:58:59Z")

</div>

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:

```julia
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

```
