Question

Is there a way to get any feedback from tSQLt.RunAll while it is running. On a very big project with high % DB Unit Test coverage this command takes ages. I would like to be able to see (and display) a progress of this command. Is it possible?

Was it helpful?

Solution

If I want to see where tSQLt has gotten to in a long list of tests, I use

SELECT Class,TestCase,Result FROM tSQLt.TestResult (NOLOCK)

which shows the results of tests executed to date in the current execution. You can join that to tSQLt.Tests:

SELECT Tests.TestClassName,Tests.Name,TestResult.Result 
FROM tSQLt.Tests (NOLOCK)
LEFT JOIN tSQLt.TestResult (NOLOCK)
 ON tSQLt.Tests.TestClassName = tSQLt.TestResult.Class
 AND tSQLt.Tests.Name = tSQLt.TestResult.TestCase

The Result column will be NULL until the test passes, fails, or errors. I'm using NOLOCK, so a dirty read, but this is sufficient for my purposes to establish progress, and prevent any interruption to the test in progress.

Hope that helps,

Dave.

OTHER TIPS

What I have done is to create a t4 template, I then run the tests via nunit all as individual tests. This means it is also very easy to integrate with your CI server. You can check out how I do it here.

Alternatively, something like this may work.

set nocount on    
create table #tests (id int identity(1,1), testclassname varchar(250), testname varchar(500))
go

insert #tests (testclassname, testname)
select testclassname, name
from tSQLt.Tests

declare @sqlCmd varchar(1000)
declare @id int
while exists(select * from #tests)
begin
    select @id = min(id) from #tests
    select  @sqlCmd = 'exec tsqlt.run ''' + testclassname + '.' + testname +''' ' from #tests where id=@id
    exec(@sqlCmd)

    delete from #tests where id = @id
end

drop table #tests
go

This will give you the result of each individual test in the messages window, but it's not that easy to follow the tests that are executing as they scroll from the bottom.

RedGate also has a test runner that you can install which allows you to run your tests from within Management Studio and it gives you feedback via a GUI.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top