0

有没有办法在运行时从 tSQLt.RunAll 获得任何反馈。在具有高 % DB 单元测试覆盖率的非常大的项目中,此命令需要很长时间。我希望能够看到(并显示)此命令的进度。可能吗?

4

2 回答 2

2

如果我想查看 tSQLt 在一长串测试中的位置,我使用

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

它显示了当前执行中迄今为止执行的测试的结果。您可以将其加入 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

在测试通过、失败或错误之前,Result 列将为 NULL。我正在使用 NOLOCK,所以是脏读,但这足以让我建立进度,并防止对正在进行的测试造成任何干扰。

希望有帮助,

戴夫。

于 2014-03-06T21:58:15.270 回答
1

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.

于 2014-03-03T11:51:57.700 回答