gpt4 book ai didi

unit-testing - 如何找到@test失败的变量值

转载 作者:行者123 更新时间:2023-12-01 00:36:06 25 4
gpt4 key购买 nike

单元测试时,了解故障点的变量值很有帮助

julia> @test a*4==2
Test Failed
Expression: a * 4 == 2
Evaluated: 4 == 2
ERROR: There was an error during testing
in record(::Base.Test.FallbackTestSet, ::Base.Test.Fail) at .\test.jl:397
in do_test(::Base.Test.Returned, ::Expr) at .\test.jl:281

例如在上面的最小测试中,显示 a 值的正确方法是什么?如果测试失败?

编辑
实际上,我正在为许多任意测试和变量寻找通用且实用的解决方案。

最佳答案

只是捕捉错误?如果您仍然希望再次抛出错误,则可以重新抛出它。

a = 2
try @test a*4 == 2
catch ex
println("a = $a")
error(ex)
end
会给:

Test Failed

Expression: a * 4 == 2

Evaluated: 8 == 2

a = 2

LoadError: ErrorException("There was an error during testing") whileloading In[44], in expression starting on line 5

in error(::ErrorException) at ./error.jl:22

关于unit-testing - 如何找到@test失败的变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41128216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com