tsqlt

Why does a tSQLt test pass in Visual Studio Test Explorer when it should fail?

早过忘川 提交于 2019-12-12 15:41:28
问题 I'm writing some tSQLt tests and running them using Visual Studio's Test Explorer via the tSQLt test adapter extension. I'm doing TDD, so I'm writing the test before writing the stored procedure that it tests. The problem is, when I run the test, it should fail because the stored procedure does not exist yet. When I run the test with tSQLt in Sql Server Management Studio it fails like it should: The module 'test_ValidCustomerName_CustomerIdIs1' depends on the missing object 'dbo.AddCustomer'.

tSQLt Testing SQL Server security permissions

谁都会走 提交于 2019-12-11 14:57:58
问题 Is there a way to test security permissions in tSQLt? Currently I am trying to test an accounts security and the results return from tSQLt are not what I am expecting. I am expecting on error that the account does not have permissions, but it appears that the "test" is using my account permissions and succeeding. EXEC tSQLt.NewTestClass @ClassName = N'TestSecurity' -- nvarchar(max) go CREATE PROCEDURE TestSecurity.[test execute as security] AS BEGIN EXECUTE AS USER = 'account3' SELECT * FROM

SQLCop tests for tSQLt

核能气质少年 提交于 2019-12-05 13:05:01
问题 The Redgate tool SQLTest for SQL unit testing now offers the ability to add tests from SQLCop however the Redgate tool only comes with few of those tests prebuild. Since tests are just stored procedures I am sure somebody has implemented more of those tests. Are you willing to share? Anyone? 回答1: I wrote SQLCop. I've been working with the fine folks over at Redgate. Originally I provided 5 (or so) tests as a proof of concept. Since then, I have also provided the remaining tests that are

TSQL Unit Test tools 2017: SQL Server Data Tools 2017 vs tSQLt

耗尽温柔 提交于 2019-12-03 12:23:15
I have a new project that needs SQL Server unit test, and CI/CD with VSTS. Below is the features that are required SQL server unit test against stored procedure, initial target tables setup for each test and clean up Unit test in sql CI/CD with VSTS and Git Easy setup and easy to use I looked into SSDT 2017, which seems good. But it seems it lacks a feature where common setup script can be shared easily between each test in Pre-Test step. It might lack other features that should be available for daily usage. But I might be wrong. Which tool fits better for general sql server unit testing in

Possible with multiple database connections

巧了我就是萌 提交于 2019-12-02 07:49:16
New to the tSQLt world (great tool set) and encountered a minor issue with a stored procedure I am setting up a test for. If I for some reason have a stored procedure which connects to mutiple databases or even multiple SQL servers (Linked Servers). Is it possible to do unit tests with tSQLt in such a scenario? I commented already, but I would like to add some more. So as I said already, that you can do anything that fits into the single transaction. But for your case I would suggest to create synonyms for every cross database/instance object and then use synonyms everywhere. I've created

How to create default constraint dependent other column in sql server

久未见 提交于 2019-12-01 19:22:52
i have a table like this tab1 create table tab1(ID int identity(1,1), Type varchar(10),IsValued bit) tab1: ID Type IsValued ---------------- 1 S 1 2 R 0 3 R 0 4 S 1 5 S 1 6 R 0 7 S 1 instead of inserting value into IsValued column i want to create one constraint(NOT TRIGGER) when Type ='S' ,IsValued should be inserted as 1 and when Type ='R' ,IsValued should be inserted as 0 like : IsValued = case when Type ='S' then 1 when Type ='R' then 0 end How can i achieve this.. twoleggedhorse You want a computed column. For example: CREATE TABLE tab1 ( ID INT IDENTITY(1,1) ,[Type] VARCHAR(10) ,IsValued

How to create default constraint dependent other column in sql server

狂风中的少年 提交于 2019-12-01 19:02:46
问题 i have a table like this tab1 create table tab1(ID int identity(1,1), Type varchar(10),IsValued bit) tab1: ID Type IsValued ---------------- 1 S 1 2 R 0 3 R 0 4 S 1 5 S 1 6 R 0 7 S 1 instead of inserting value into IsValued column i want to create one constraint(NOT TRIGGER) when Type ='S' ,IsValued should be inserted as 1 and when Type ='R' ,IsValued should be inserted as 0 like : IsValued = case when Type ='S' then 1 when Type ='R' then 0 end How can i achieve this.. 回答1: You want a

How to ROLLBACK a transaction when testing using tSQLt

大城市里の小女人 提交于 2019-12-01 05:37:23
I recently was calling a procedure that contained a rasierror in the code. The raiserror was in a try catch block. Also a BEGIN TRAN was in the same try catch block after the raiserror. The Catch block is designed to ROLLBACK the transaction if the error occurred in the transaction. The way it does this is to check the @@TRANCOUNT if it is greater that 0 I know that it had started a transaction and needs to ROLLBACK. When testing with tSQLt the @@TRANCOUNT is always >0 so if it ever hits the CATCH Block the ROLLBACK is executed and tSQLt fails (because tSQLt is running in a transaction). When

Unit testing of SSIS Package with tSQLt

最后都变了- 提交于 2019-11-30 21:22:36
I really like tsqlt to test procs and functions, but really would like to be able to also execute SSIS packages and take advantage of FakeTable and AssertEquals to determine if it was the SSIS package did what it was supposed to. Has anyone explored this path, is it possible to call dtexec from with the transaction that tsqlt wraps your test in? I believe I can answer your question Andrey, although this is a little late in coming. But I believe that it will benefit others. We are using RedGate SQLTest(tSQLt) to do data quality testing as a part of our integration testing. For example to test

Unit testing of SSIS Package with tSQLt

折月煮酒 提交于 2019-11-30 17:08:06
问题 I really like tsqlt to test procs and functions, but really would like to be able to also execute SSIS packages and take advantage of FakeTable and AssertEquals to determine if it was the SSIS package did what it was supposed to. Has anyone explored this path, is it possible to call dtexec from with the transaction that tsqlt wraps your test in? 回答1: I believe I can answer your question Andrey, although this is a little late in coming. But I believe that it will benefit others. We are using