how to get an average of unit test results in sql server db

55 Views Asked by At

So i'm trying to find a monthly average of unit tests my employer runs. The table consists of test id, start date, end date, total tests, duration l, pass total , fail total and pass perc . I'm not sure how to pull this off (i'm a new apprentice)

I've tried a couple or suggestions :

SELECT AVG(a.COUNT) AS avg
from (
    select count (*) as count, month(Passed) as month
    from UnitTestRun
    group by mnth
) as a


select count(*)/count(distinct month('EndDate')) from UnitTestRun

Edit: Test id: 10 Start date: 2022-02-07 End date: 2022-02-07 Total tests: 507 Dduration: 868600000 Pass total: 495 Fail total: 12 Pass perc: 97.63

Feburary average = ...%

1

There are 1 best solutions below

1
Venkat On

By categorizing the data by month and averaging the numbers, one may determine the average number of unit tests performed each month.

SELECT AVG(a.count) AS avg
FROM (
    SELECT COUNT(*) AS count, MONTH(Passed) AS month
    FROM UnitTestRun
    GROUP BY MONTH(Passed)
) AS a;

By averaging the pass % field in the table, the second query determines the total average pass percentage.

SELECT AVG(pass_perc) AS avg_pass_perc
FROM UnitTestRun;