# Is there a way to handle test case names?

**URL:** https://discourse.julialang.org/t/is-there-a-way-to-handle-test-case-names/76173
**Category:** General Usage
**Tags:** testing
**Created:** [February 10, 2022, 3:08pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-handle-test-case-names/76173 "2022-02-10T15:08:09Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ReneUmmels](https://avatars.discourse-cdn.com/v4/letter/r/cab0a1/32.png) [@ReneUmmels](https://discourse.julialang.org/u/ReneUmmels)
#### Post date: [February 10, 2022, 3:08pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-handle-test-case-names/76173/1 "2022-02-10T15:08:09Z")

</div>

with @testset you can specify a set name  
can the same be done with @test somehow? Maybe by creating own extension for test macro, if so how?

Background:  
Sometimes I want to have sets but also name the individual test cases in a set to make it more verbose for other developers what is exactly tested (and whether the individual test case is normal case or corner case, and so on).

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [February 10, 2022, 3:17pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-handle-test-case-names/76173/2 "2022-02-10T15:17:09Z")

</div>

I would just use code comments for this. I mean… I don’t. But if I wanted to be more thorough I would.

EDIT: My reasoning is that while I often look at the `runtests.jl` for a package, I almost never actually run the tests and look at the output unless I am developing a package. In that case, I would have already looked at the test code anyways.

---

<div class="post-metadata">

### Author: ![ReneUmmels](https://avatars.discourse-cdn.com/v4/letter/r/cab0a1/32.png) [@ReneUmmels](https://discourse.julialang.org/u/ReneUmmels)
#### Post date: [February 10, 2022, 3:23pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-handle-test-case-names/76173/3 "2022-02-10T15:23:52Z")

</div>

I am looking for a non-comment solution  
as I want to see the test case names in the output of test run

---

<div class="post-metadata">

### Author: ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)
#### Post date: [February 10, 2022, 10:06pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-handle-test-case-names/76173/4 "2022-02-10T22:06:39Z")

</div>

You could wrap every test in a testset if that’s the end result you want. You could extend the `@test` macro for that like you suggested if that makes it simpler.

```julia
macro namedtest(name, test)
    esc(:(@testset $name begin @test $test end))
end

```

```julia
julia> @namedtest "test 1" 1 == 1
Test Summary: | Pass Total
test 1 | 1 1

```

Note that nested testsets don’t print if they pass:

```julia
julia> @testset "a bunch of tests" begin
           @namedtest "test 1" 1 + 1 == 2
           @namedtest "test 2" 1 * 1 == 1
       end
Test Summary: | Pass Total
a bunch of tests | 2 2

```

So I don’t know if this will get you the effect you want either.

---

<div class="post-metadata">

### Author: ![ReneUmmels](https://avatars.discourse-cdn.com/v4/letter/r/cab0a1/32.png) [@ReneUmmels](https://discourse.julialang.org/u/ReneUmmels)
#### Post date: [March 9, 2022, 2:44pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-handle-test-case-names/76173/5 "2022-03-09T14:44:19Z")

</div>

It looks okay-ish

```julia
Test Summary: | Pass Total
a bunch of tests | 2 2
Test.DefaultTestSet("a bunch of tests", Any[Test.DefaultTestSet("test 1", Any[], 1, false, false), Test.DefaultTestSet("test 2", Any[], 1, false, false)], 0, false, false)

Test Summary: | Pass Fail Total
a bunch of tests | 1 1 2
  test 1 | 1 1
  test 2 | 1 1
ERROR: Some tests did not pass: 1 passed, 1 failed, 0 errored, 0 broken.

```

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [March 9, 2022, 5:16pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-handle-test-case-names/76173/6 "2022-03-09T17:16:39Z")

</div>

Is the `@testset my_func()` functionality somewhat close to what you’re looking for? [It’s been merged for a while](https://github.com/JuliaLang/julia/pull/42518), but I don’t know if it’s in a release yet. Possibly will only be released in 1.8.
