我创建了一个简单的数据库来存储测试结果,但是我正在努力使用 SQL 计数来汇总我的通过/失败/警告来呈现这个。
这个想法是测试运行(TRID)将有几个测试集(TSID),每个测试集都有几个测试用例(TCID)。
- 该 TSID 的测试用例总数应该相等
- 通过的测试用例数量应该相等,所有步骤的 StatusID=1
- Fail 应该与 StatusID=2 的 1 个或多个步骤的测试用例数量相等。
- 警告应该有相同数量的测试用例,1 个或多个 StatusID=3 步骤,但相同的测试用例应该有零失败。如果有一个失败的步骤,那么测试用例应该按照上面的方法失败。
SQL 创建我的结果表的简化示例:-
create table Results (StatusID int, TRID int, TSID int, TCID int);
--Test Set 1 / Test Case 1.
INSERT INTO Results VALUES (1, 1, 1, 1)
INSERT INTO Results VALUES (1, 1, 1, 1)
INSERT INTO Results VALUES (1, 1, 1, 1)
--Test Set 1 / Test Case 2
INSERT INTO Results VALUES (1, 1, 1, 2)
INSERT INTO Results VALUES (1, 1, 1, 2)
--Test Set 2 / Test Case 1
INSERT INTO Results VALUES (1, 1, 2, 1)
INSERT INTO Results VALUES (1, 1, 2, 1)
INSERT INTO Results VALUES (1, 1, 2, 1)
--Test Set 2 / Test Case 2
INSERT INTO Results VALUES (1, 1, 2, 2)
INSERT INTO Results VALUES (2, 1, 2, 2)
--Test Set 3 / Test Case 1
INSERT INTO Results VALUES (1, 1, 3, 1)
INSERT INTO Results VALUES (1, 1, 3, 1)
INSERT INTO Results VALUES (1, 1, 3, 1)
--Test Set 3 / Test Case 2
INSERT INTO Results VALUES (1, 1, 3, 2)
INSERT INTO Results VALUES (3, 1, 3, 2)
--Test Set 4 / Test Case 1
INSERT INTO Results VALUES (1, 1, 4, 1)
INSERT INTO Results VALUES (1, 1, 4, 1)
INSERT INTO Results VALUES (1, 1, 4, 1)
--Test Set 4 / Test Case 2
INSERT INTO Results VALUES (3, 1, 4, 2)
INSERT INTO Results VALUES (2, 1, 4, 2)
SELECT * FROM Results
我当前的 SQL(您将看到它为我提供了错误的警告计数:-
DECLARE @trid INT
SET @trid = 1
SELECT TRID, TSID,
(SELECT COUNT(DISTINCT TCID) FROM Results WHERE R.TRID = @trID AND R.TSID = TSID) As Total,
(SELECT COUNT(DISTINCT TCID) FROM Results WHERE TRID = @trID AND R.TSID = TSID) - (SELECT COUNT(DISTINCT TCID) FROM Results WHERE TRID = @trID AND R.TSID = TSID AND StatusID = 2) - (SELECT COUNT(DISTINCT TCID) FROM Results WHERE TRID = @trID AND R.TSID = TSID AND StatusID = 3 AND (SELECT COUNT(DISTINCT TCID) FROM Results WHERE TRID = @trID AND R.TSID = TSID AND StatusID = 2) = 0) AS Pass,
(SELECT COUNT(DISTINCT TCID) FROM Results WHERE R.TSID = TSID AND StatusID=2) As Fail,
(SELECT COUNT(DISTINCT TCID) FROM Results WHERE R.TSID = TSID AND StatusID=3) As Warning
FROM Results R
WHERE TRID = @TRID
GROUP BY TRID, TSID
从上面的SQL来看,目前不正确的结果是:-
TRID TSID Total Pass Fail Warning
1 1 2 2 0 0
1 2 2 1 1 0
1 3 2 1 0 1
1 4 2 1 1 1*
结果应该是......
TRID TSID Total Pass Fail Warning
1 1 2 2 0 0
1 2 2 1 1 0
1 3 2 1 0 1
1 4 2 1 1 0*
谢谢