gpt4 book ai didi

testing - 如何根据逻辑表达式生成测试数据?

转载 作者:行者123 更新时间:2023-11-28 21:24:10 29 4
gpt4 key购买 nike

作为主题,我想生成测试数据以涵盖某些逻辑表达式的所有可能条件,如下所示:

 ((a==3000710)||(b==3000700))
&&(b>=30 && b<=33)
&&((c==1)||(c>=4 && c<=6))
&&((v==1.0.9)||(v==2.0.0))

欢迎任何评论。

顺便说一句,逻辑表达式是应用在我们后端服务器上的简化规则。

最佳答案

我必须说的第一件事 - 重构它!将其分解为几个 if 语句,这样更容易验证、反转逻辑并提前退出。在没有看到实际代码和上下文的情况下,很难给出更详细的建议。

另一件事,如果(b == 3000700) , 然后 &&(b>=30 && b<=33)返回 false,这使得语句的这一部分 ||(b==3000700)无意义。也许它应该是 (a == 3000700)

关于测试用例...再一次,如果没有看到完整的代码片段并且不知道上下文,那么提供有意义的建议有点困难。但无论如何我都会尝试。

让我们看看每个变量的“临界值”。

  • 变量 a:3000710 , 任何其他
  • 变量 b:3000700, [30, 33], any
    other
  • 变量 c:1, [4, 6], any other
  • 变量 v:1.0.9, 2.0.0, any other

使用测试理论(等价划分和边界值分析)我们可以限制上面列出的“临界”值。

[30, 33] => 30, 31, 33 (The value outside of this range is already covered by "any other")
[4, 6] => 4, 5, 6 (The value outside of this range is already covered by "any other". Though we did't really change anything in this case)

Nunit 有一个属性 [Combinatorial]它为测试参数提供的各个数据项的所有可能组合生成测试用例。

*做出的假设:变量 a, b, c是int类型,变量v是字符串

代码看起来像这样:

        [Test, Combinatorial]        
public void FirstTest(
[Values(3000710, 0)] int a,
[Values(30, 31, 33, 3000700, 0)] int b,
[Values(1, 4, 5, 6, 0)] int c,
[Values("1.0.9", "2.0.0", "")] string v)
{
RunTestMethod(a, b, c, v);
}

您只需要在测试执行时存储生成的测试数据

关于testing - 如何根据逻辑表达式生成测试数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44898987/

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