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
Is there anything like the following?
@test "Testing dummy equality" 1==0
Thank you for your help,
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
You could, of course, write your own functions that include labels, e.g.
==ᴸ(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.)
Thank you but this does not print the string like @testset. I guess I am looking for a “short”
If the goal is to print the label and a pass/fail, then maybe this’ll do the trick:
function print_test(label, cond)
printstyled("$label: ", color=:normal)
and an example usage would look like:
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.
I just use lots of short testsets.
You could define:
macro testL(label, args...)
:(@testset $label begin @test $(args...); end)
and then you can do
@testL "Test dummy equality" 1==0