gpt4 book ai didi

unit-testing - [在此处插入语言] 的测试框架

转载 作者:行者123 更新时间:2023-11-28 19:57:33 25 4
gpt4 key购买 nike

我正在寻找一个测试框架来为 a language without much test support 引入自动化测试.据我所知,我需要一个能够使用某种形式的协议(protocol)运行 VDF 测试的框架。我宁愿把时间花在编写测试上,也不愿花时间编写 VDF 代码来与测试框架交互,因此更喜欢轻量级协议(protocol)。

Slim with Fitnesse似乎是个不错的候选人,但我对所有推荐感兴趣。

能够跨编程语言使用相同的测试框架将是一个额外的好处。

最佳答案

这假设您在 API 级别工作。如果我读错了,而你在 GUI 级别工作,你更倾向于考虑像 selenium 或 watir 这样的东西。

您是否考虑过编写自己的简单测试框架来输出 TAP 结果(测试任何协议(protocol))- 然后使用 grind 或 TAP2HTML 对其进行解析?

说真的,TAP 输出看起来像这样:

1..7ok 1 - hello world with null value returns 'hello world' stringok 2 - hello world with bob returns 'hello, bob'ok 3 - hello world with 123 return 'hello, 123'ok 4 - hello world with 5K string return hello plus stringok 5 - special charactersok 6 - internationalization, frok 7 - internationalization, jaLooks like you failed 0 tests of 7.

(如果它在第 5 步后死了,1..7 会告诉你有问题)

输出是直接的 ASCII。你基本上有两个全局变量,numTestsTotal 和 numTestExecuted,并像这样编写函数:

sub ok (boolean bExpected, string comment) {  if (bExpected) {    print "ok " . numTestsExecuted . " "  . comment . "\n";      }else {    print "not ok" . numTeststotal . " " . comment . "\n";  }  numTestsExecuted++;}sub eq(int iExpected, int iResult, string comment) {  if (iExpected==iResult) {     print "ok " . numTestsExecuted . " " . comment . "\n";  } else {     print "not ok" . numTestsExecuted . " " . comment . \n";  }  numTestsExecuted++;}

您在库中编写常规代码,然后您的测试应用程序包含库和测试模块。

可以为每种类型的值重载eq,write是比较数组等。

请参阅有关 TAP 的文档: http://testanything.org/wiki/index.php/Main_Page

Test::More

是的,您可以争辩说 eq() 应该“只是”调用 ok()。或者您可以在输出中插入预期和实际结果。由你决定。

无论如何,对于命令式语言来说,有很多 TAP 解析器和解释器。

关于unit-testing - [在此处插入语言] 的测试框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/851144/

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