Gnat测试的文档展示了如何生成线束和骨架单元测试。它为目标项目中的每个公共函数创建一个单元测试,但是如果我添加另一个单元测试,当我重新生成线束和骨架单元测试时,它会被覆盖。
在 gnattest 提供的简单示例项目中,如何添加另一个测试?我试过了:
(1) 将另一个 Assert 行添加到已经存在的测试函数中。这行得通,但不是好的做法;第一个失败的测试会阻止其他测试运行。
(2)在obj/gnattest/harness/gnattest.xml中添加函数定义,然后重新生成测试不起作用;xml 文件在用于创建测试存根之前重新生成。
(3) 通过以下更改手动将定义添加到测试/和利用/,这些更改会因重新生成测试而受到破坏。
将此添加到 obj/gnattest/tests/simple-test_data-tests.ads:
procedure Test_Inc2_4f8b9f (Gnattest_T : in out Test);
将此添加到 obj/gnattest/tests/simple-test_data-tests.adb:
-- begin read only
procedure Test_Inc2 (Gnattest_T : in out Test);
procedure Test_Inc2_4f8b9f (Gnattest_T : in out Test) renames Test_Inc2;
-- id:2.2/4f8b9f38b0ce8c74/Inc/1/0/
procedure Test_Inc2 (Gnattest_T : in out Test) is
-- simple.ads:7:4:Inc
-- end read only
begin
Assert (Inc(2) = 2, "this test should fail");
-- begin read only
end Test_Inc2;
-- end read only
将声明添加到第 16 行,并将 create 和 add_test 添加到 obj/gnattest/harness/simple-test_data-tests-suite.adb 中的 Suite 函数:
Case_1_1_Test_Inc2_4f8b9f : aliased Runner_1.Test_Case;
Runner_1.Create
(Case_1_1_Test_Inc2_4f8b9f,
"simple2.ads:7:4:",
Test_Inc2_4f8b9f'Access);
Result.Add_Test (Case_1_1_Test_Inc2_4f8b9f'Access);
要重新编译,不要使用 Makefile,因为这会破坏更改。相反,运行
gprbuild -Pobj/gnattest/harness/test_driver.gpr
./obj/gnattest/harness/test_runner.exe`.
必须有更好的方法。