How to test a trigger?

Easy unit testing for databases in SQL Server Management Studio

Moderators: JonathanWatts, David Atkinson, Anu Deshpande, Michelle Taylor, David Priddle

How to test a trigger?

Postby AdamY » Thu Mar 28, 2013 9:19 pm

TableA has Trigger1 that inserts data into TableB. I'd like to test that the trigger works correctly. Can I do that with SQL Test? I haven't been able to find a way yet. Does FakeTable handle triggers?
AdamY
 
Posts: 41
Joined: Fri Oct 15, 2010 8:24 pm

Postby stanori » Fri Mar 29, 2013 10:22 pm

Hi AdamY,

Thanks for your post. It looks like something simliar has been covered in stackoverflow:

http://stackoverflow.com/questions/1355 ... e-triggers

It looks like there is a workaround solution to make this happen.

Best Regards,
Steve
_________________
Steve Tanori
Product Support
Red Gate Software Ltd.
866-997-0378
stanori
 
Posts: 84
Joined: Mon Apr 23, 2012 1:13 pm

Postby AdamY » Fri Oct 04, 2013 5:40 pm

kenbroz - the answer Steve (stanori) posted has a link to a work-around solution. tSQLt is working on a permanent solution, I think. The tSQLt Google Group is very helpful and has more info, too.
AdamY
 
Posts: 41
Joined: Fri Oct 15, 2010 8:24 pm

Re:

Postby datacentricity » Mon Oct 07, 2013 3:22 pm

kenbroz wrote:why has been answered, I would like to know the answer because it has a similar problem.


The latest version of tSQLt (the framework that underpins RedGate's SQL Test) now has an ApplyTrigger method which used in conjunction with FakeTable should allow you to do test your trigger. Not sure of this version is packaged up with SQL test yet though.

I have successfully used SQL Test with a more recent build of tSQLt (based on the SQL script download via tsqlt.org) but YMMV.
\"Your mind is like a parachute, it works best when open\" Frank Zappa
\"Be wary of strong drink. It can make you shoot at tax collectors…and miss\" Robert Heinlein
blog: http://datacentricity.net
twitter: @datacentricity
datacentricity
 
Posts: 19
Joined: Wed Jul 18, 2012 12:22 pm
Location: London


Return to SQL Test

Who is online

Users browsing this forum: No registered users and 0 guests