在@testset中调查或打印失败的@test的更多细节(函数的打印输入变量,迭代次数等)的首选方法是什么? 我试图围绕它包装一个try-catch-block。然而,它似乎并没有发生。
以下是一个简单的例子:
using Base.Test
rng = MersenneTwister(3231);
# define function that works different than expected
function compare(a,b)
if a == 3 && b == 3
return false
else
return a == b
end
end
# test function in a test set
@testset "Test Compare Function" begin
for iii = 1:10
number = rand(rng,1:10)
try
@test compare(number,number) == true
catch
@show(number)
end
end
end
非常感谢!
答案 0 :(得分:1)
您需要确保在打印后进行测试。
@testset "Test Compare Function" begin
for iii = 1:10
number = rand(rng,1:10)
@test begin
res = compare(number,number) == true
if !res
@show number
flush(STDOUT)
end
res
end
end
end