您可以使用lgtunit
. 这里总结了它的主要特点。您的大多数测试都可以按原样运行或轻松转换。使用您的示例:
:- 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.
该工具支持多种测试方言,其中一些是通用的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 标准合规套件提供了大量示例。
您还可以导出多个行业标准(如 TAP 和 xUnit)的测试结果并生成报告以便于浏览(参见例如https://infradig.github.io/treella/)。
有关测试的进一步建议,另请参阅这些博客文章。