unit-testing - GNU Prolog 中的单元测试

标签 unit-testing prolog gnu-prolog

我正在尝试将我的 SWI Prolog 应用程序迁移到 GNU Prolog。不幸的是,我对单元测试有疑问。在 SWIPL 中,我们可以简单地使用 plunit模块并编写如下测试用例:

:- begin_tests(my_tests).
test(my_predicate_test) :- my_predicate(Result), assertion(Result == [foo, bar]).
test(second_test) :- foo(10, X), assertion(X == "hello world").
:- end_tests(my_tests).
但是如何在 GNU Prolog 中实现单元测试呢?甚至一些额外的库,如 crisp不适用于 gprolog。

最佳答案

您可以使用 lgtunit .其主要特点总结here .您的大多数测试都可以按原样运行或轻松转换。使用您的示例:

:- object(tests, extends(lgtunit)).

    :- uses(lgtunit, [assertion/1]).
    :- uses(user, [my_predicate/1, foo/2]).

    test(my_predicate_test) :-
        my_predicate(Result),
        assertion(Result == [foo, bar]).

    test(second_test) :-
        foo(10, X),
        assertion(X == "hello world").

:- end_object.
该工具支持多个test dialects ,其中一些为 plunit 所共有.例如。
:- object(tests, extends(lgtunit)).

    :- uses(user, [my_predicate/1, foo/2]).

    test(my_predicate_test, true(Result == [foo, bar]) :-
        my_predicate(Result).

    test(second_test, true(X == "hello world")) :-
        foo(10, X).

:- end_object.
假设您正在测试纯 Prolog 代码(假设您使用的是 GNU Prolog),Logtalk 的 Prolog 标准 compliance suite提供了大量的例子。
您还可以以多种行业标准(例如 TAP 和 xUnit)导出测试结果,并生成报告以便于浏览(参见例如 https://infradig.github.io/trealla/)。
有关测试的更多建议,另请参阅 blog posts .

关于unit-testing - GNU Prolog 中的单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65844487/

相关文章:

unit-testing - 为 PHPUnit 中的所有单元测试模拟我的数据库

prolog - 未捕获异常 : error(existence_error(procedure, likes/0),friend/0)(七种语言)

prolog - 定义一个关系first_last(L1, L2),它接受列表L1并返回包含L1的前三个和最后三个元素的列表L2

prolog - 如何在 GNU Prolog 中使用 "long int"?

visual-studio-2010 - Nunit 未在 Visual Studio Debug模式下运行 SetUp 方法

c# - 如何使用最小起订量测试调用 protected 助手的代码

list - Prolog 查找列表中的中间元素

prolog - 制作适用于 GNU 和 SWI 的 Prolog 代码

php - 单元测试开始前出现 "Updating PHPUnit Version..."窗口