SQLCover
SQLCover copied to clipboard
Trigger coverage
Hi,
I just started using tSQLt and will be very helpful if I can build coverrage to the test. Thanks for your helpful tool and articles!
But I seems found a bug, SQLCover doesn't seems to cover logic in a trigger
How to reproduce
- Have a table A with insert trigger T
- Fake table A
- Apply trigger T to faked table A
- Create test to perform insert to table A, trigger T is executed
- Run SQLCover
Expected behavior: SQLCover reports code coverage in trigger T
Actual behavior: SQLCover shows no code coverage in trigger T
This reproduction steps are executed in SQL Server 12.0.4100.1
Thanks Hendra
Hi Hendra,
It is because ApplyTrigger creates a new object and we use an object cache to lookup the name - when we generate the list of names it hasn't been re-created again.
I will try to include the fix to this in an upcoming release.
Ed
Hi Ed,
Thanks for your explanation, just looked into tSQLt's ApplyTrigger code and yes you're right it copies the original trigger to apply to target table. I was assuming it use the original trigger, so I thought it was a bug in SQLCover :)
Thanks for considering this as one of feature request as part of the upcoming release. Any ETA? :)
Thanks again, Hendra
I'll have a look and see how easy it will be to add in - which version of sql do you use? It might be easier on newer versions of sql (2012+)
ed
Hi,
The database project under test has its compatibility level set to SQL Server 2008. But it always deployed to at least SQL Server 2012+. One of the plan is once we have a good coverage, we can raise the compatibility level to latest version.
But if necessary, I think I can up the compatibility level to SQL Server 2012 for testing purpose.
Hendra
I seem to be facing the same problem using SQL Server 2016 in combination with tSQLt.
Is it correct that this issue still exists or is there a fix for this (student here)?
This won't be possible until tSQLt adds some code on their side. I have some extra changes I added to tSQLt and SQL Cover to make this work. I have a fork of this project that has these changes and it has been updated to .Net Core 3.1.
I'm just waiting for tSQLt to add their part so I can create a PR into this repo
@martinisaksen is this still waiting on tSQLt?
I don't remember my PR ever getting merged so it is probably still waiting on that.
Hiya @martinisaksen Seeing as this project seems to be dead, have you moved to another, or still working on your own copy?
We're looking at using this fork https://github.com/sayantandey/SQLServerCoverage
and having triggers covered would be handy!
I haven't worked in SQL Server for a few years. The trigger changes weren't too bad and should still be in the forked repos I have for them. There is one change in tSQLt to track triggers better and then the change in this repo to include it in code coverage.
Feel free to grab those changes if you want.
On Wed, Aug 9, 2023, 10:07 AM sgtwilko @.***> wrote:
Hiya @martinisaksen https://github.com/martinisaksen Seeing as this project seems to be dead, have you moved to another, or still working on your own copy?
We're looking at using this fork https://github.com/sayantandey/SQLServerCoverage
and having triggers covered would be handy!
— Reply to this email directly, view it on GitHub https://github.com/GoEddie/SQLCover/issues/17#issuecomment-1671825339, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEGVV5TYIENBWKQZQ3YKEBLXUO7VJANCNFSM4DBNCE6A . You are receiving this because you were mentioned.Message ID: @.***>