# Test with title string

**URL:** https://discourse.julialang.org/t/test-with-title-string/29566
**Category:** General Usage
**Tags:** testing
**Created:** [October 6, 2019, 8:55pm UTC](https://discourse.julialang.org/t/test-with-title-string/29566 "2019-10-06T20:55:47Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)
#### Post date: [October 6, 2019, 8:55pm UTC](https://discourse.julialang.org/t/test-with-title-string/29566/1 "2019-10-06T20:55:47Z")

</div>

Hi,

I am doing some testing for a package and I would like to have a string attached to the test result. Right now, I have to use `@testset` with a `begin` keyword.

Is there anything like the following?

```julia
@test "Testing dummy equality" 1==0

```

Thank you for your help,

Best

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [October 7, 2019, 3:39am UTC](https://discourse.julialang.org/t/test-with-title-string/29566/2 "2019-10-07T03:39:43Z")

</div>

No, as far as I can tell the `Base.Test` module does not provide any way to label individual tests except by putting them into a `@testset`.

You could, of course, write your own functions that include labels, e.g.

```julia
==ᴸ(a,b; label="") = a == b
@test 1 ==ᴸ 0 label="Testing dummy equality"

```

(Keyword arguments on the `@test` line are passed to the function call in the first expression.)

---

<div class="post-metadata">

### Author: ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)
#### Post date: [October 7, 2019, 5:30am UTC](https://discourse.julialang.org/t/test-with-title-string/29566/3 "2019-10-07T05:30:52Z")

</div>

> [@stevengj](#):
>
> ==ᴸ(a,b; label=“”) = a == b @test 1 ==ᴸ 0 label=“Testing dummy equality”

Thank you but this does not print the string like @testset. I guess I am looking for a “short” `@testset`

---

<div class="post-metadata">

### Author: ![zaki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zaki/32/10300_2.png) [@zaki](https://discourse.julialang.org/u/zaki)
#### Post date: [October 7, 2019, 7:28am UTC](https://discourse.julialang.org/t/test-with-title-string/29566/4 "2019-10-07T07:28:50Z")

</div>

If the goal is to print the label and a pass/fail, then maybe this’ll do the trick:

```julia
function print_test(label, cond)
    printstyled("$label: ", color=:normal)
    if cond
        printstyled("PASS", color=:green)
    else
        printstyled("FAIL", color=:red)
    end
    print("\n")
end

```

and an example usage would look like:

```julia
print_test("Testing dummy equality", 1==0)

```

However, since this doesn’t use `@test`, there won’t be any useful error messages if the test fails and it won’t be counted within a testset block.  
A possible workaround is to return true/false from the `print_test()` function, then it can be called by `@test print_test(...)`. That’ll make the test count, but any error messages will still be useless probably.

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [October 7, 2019, 7:31am UTC](https://discourse.julialang.org/t/test-with-title-string/29566/5 "2019-10-07T07:31:45Z")

</div>

I just use lots of short testsets.  
Often nested

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [October 7, 2019, 10:13am UTC](https://discourse.julialang.org/t/test-with-title-string/29566/6 "2019-10-07T10:13:54Z")

</div>

> [@rveltz](#):
>
> Thank you but this does not print the string like `@testset`. I guess I am looking for a “short” `@testset`

You could define:

```julia
using Test
macro testL(label, args...)
    :(@testset $label begin @test $(args...); end)
end

```

and then you can do

```julia
@testL "Test dummy equality" 1==0

```

for example.

---

<div class="post-metadata">

### Author: ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)
#### Post date: [October 7, 2019, 10:20am UTC](https://discourse.julialang.org/t/test-with-title-string/29566/7 "2019-10-07T10:20:23Z")

</div>

Wonderfull! Thank you
