当然!这是逐步指南,将您的测试SQL脚本添加到您的年龄源代码。
在以源代码安装您的功能后,您必须使用它附加测试套件才能将其合并到项目的存储库中。
因此,如果您需要学习如何将第一个功能添加到源代码中,则可以在我的博客上找到该功能。
首先,您必须意识到遵循的测试策略。
我们主张其输出具有前运行脚本输出的SQL脚本。
例如:
INSERT 1 INTO tbl;
SELECT * FROM tbl;
-----
num
-----
1
这是输出SQL,例如test.out
SQL脚本它会仅具有命令
即
INSERT 1 INTO tbl;
SELECT * FROM tbl;
这样,我们可以将预制输出与SQL脚本进行比较。
apache年龄测试是回归目录。
它包含:
- 预期
- sql
我们将不得不将测试套件添加到的目录。
SQL脚本中的SQL Directory和SQL.Out到预期目录中。
但是,如果我们有一个很大的脚本,我们如何获得输出文件包含SQL命令及其输出而无需进行复制和粘贴。
我们如何自动化?
例如,在添加age_fact()函数之后;阶乘功能。
我创建了以下脚本进行测试:
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
LOAD 'age';
SET search_path TO ag_catalog;
SELECT create_graph('math_test');
-- Factorial function tests age_fact()
-- 0! = 1
SELECT * FROM age_fact(0);
-- 1! = 1
SELECT * FROM age_fact(1);
-- 5! = 120
SELECT * FROM age_fact(5);
-- 10! = 3628800
SELECT * FROM age_fact(100);
-- 20! = 2432902008176640000
SELECT * FROM age_fact(500);
-- Overflow test
SELECT * FROM age_fact(32178);
-- Inside the cypher query
-- At CREATE clause
SELECT * FROM cypher('math_test', $$
CREATE (n:Node {value: fact(5)})
RETURN n.value
$$) AS (value agtype);
-- At MATCH clause
SELECT * FROM cypher('math_test', $$
MATCH (n:Node {value: fact(5)})
RETURN n.value
$$) AS (value agtype);
-- At RETURN clause
SELECT * FROM cypher('math_test', $$
MATCH (n:Node {value: fact(5)})
RETURN fact(toInteger(n.value))
$$) AS (value agtype);
-- At WHERE clause
SELECT * FROM cypher('math_test', $$
MATCH (n:Node)
WHERE n.value = fact(5)
RETURN n.value
$$) AS (value agtype);
-- At SET clause
SELECT * FROM cypher('math_test', $$
MATCH (n:Node)
SET n.value = fact(3)
RETURN n.value
$$) AS (value agtype);
-- CLEANUP
SELECT * FROM drop_graph('math_test', true);
-- End of math.sql
在SQL脚本之上具有Apache许可证是强制性的
解决手动输出的问题的关键点是
失败然后通过
- 运行回归测试
- 让它失败并获取输出/your_test.out
- 将其移至预期。
- 重新运行测试
- (一切都过去)