多くの列を返すクエリからメタデータを確認するのにtSQLt AssertResultSetsHaveSameMetaData
を使用しようとしています。tSQLt AssertResultSetsHaveSameMetaData SQLTestで切り捨てられた応答メッセージ
「期待されていたものの詳細」のメッセージが切り捨てられているため、2つの情報で何が間違っているのかわかりません。 メッセージを出力して(たとえばファイルに)切り捨てないようにする方法はありますか?
多くの列を返すクエリからメタデータを確認するのにtSQLt AssertResultSetsHaveSameMetaData
を使用しようとしています。tSQLt AssertResultSetsHaveSameMetaData SQLTestで切り捨てられた応答メッセージ
「期待されていたものの詳細」のメッセージが切り捨てられているため、2つの情報で何が間違っているのかわかりません。 メッセージを出力して(たとえばファイルに)切り捨てないようにする方法はありますか?
テストを実行する前にEXEC [tSQLt].[XmlResultFormatter];
を試すことができます。これは「サーバーの構築」シナリオでの使用を意図していますが、SSMSでより多くの出力を表示するためには、おそらくサービスに入る可能性があります。
実際にテストしている内容によって異なります。私は、AssertResultsSetsHaveSameMetaDataの出力がワイドな結果セットでは、扱いにくいということに同意します。あなたはこの(少し異なる)のアプローチを使用できビューの一方で
create procedure [ProcedureTests].[test SelectProcedure result set contract] as begin create table #expected ( name varchar(500) not null , column_ordinal int not null identity(1,1) , system_type_name varchar(500) not null , Nullability varchar(16) not null ) ; with expectedCte (name, system_type_name, Nullability) as ( select 'ItemId' , 'int' , 'not null' union all select 'ActorId' , 'int' , 'not null' union all select 'LanId' , 'nvarchar(200)' , 'not null' union all select 'ConsumerId' , 'int' , 'not null' union all select 'ConsumerMoniker' , 'nvarchar(200)' , 'not null' union all select 'ProfileTypeId' , 'int' , 'not null' union all select 'ProfileTypeName' , 'varchar(50)' , 'not null' union all select 'ProfileId' , 'int' , 'not null' ) insert #expected ( name , system_type_name , Nullability ) select name, system_type_name, Nullability from expectedCte; --! Act select name , column_ordinal , system_type_name , case is_nullable when 1 then 'null' else 'not null' end as [Nullability] into #actual from sys.dm_exec_describe_first_result_set_for_object(object_id('mySchema.SelectProcedure'), 0); --! Assert exec tSQLt.AssertEqualsTable #expected, #actual; end; go
:でも任意の故障のでは
alter procedure [ViewTests].[test ViewName resultset contract] as begin create table [ViewTests].[expected] ( TransactionId int not null , SourceId int not null , SourceKey nvarchar(50) not null , TransactionTypeId int not null , TransactionStatusId int not null , LastModified datetime not null ); --! You comparison may be as simple as this (but see alternative approach below) exec tSQLt.AssertEqualsTableSchema '[ViewTests].[expected]', 'mySchema.ViewName'; --! --! Seems that is_nullable column on dm_exec_describe_first_result_set (used by tSQLt.AssertEqualsTableSchema) --! can be a bit flakey where views are concerned so you may need to ignore nullability when testing --! this view (so comment out that column in both SELECTs) --! select c.name as [ColumnName] , c.column_id as [ColumnPosition] , case when st.name in ('char', 'varchar', 'varbinary') then st.name + '(' + case when c.max_length = -1 then 'max' else coalesce(cast(c.max_length as varchar(8)), '???') end + ')' when st.name in ('nchar', 'nvarchar') then st.name + '(' + case when c.max_length = -1 then 'max' else coalesce(cast(c.max_length/2 as varchar(8)), '???') end + ')' when st.name in ('decimal', 'numeric') then st.name + '(' + coalesce(cast(c.precision as varchar(8)), '???') + ',' + coalesce(cast(c.scale as varchar(8)), '???') + ')' when st.name in ('time', 'datetime2', 'datetimeoffset') then st.name + '(' + coalesce(cast(c.precision as varchar(8)), '???') + ')' else st.name end as [DataType] , c.[precision] as [NumericScale] , c.scale as [NumericPrecision] , c.collation_name as [CollationName] , cast(case c.is_nullable when 1 then 'null' else 'not null' end as varchar(16)) as [Nullability] into #expected from sys.columns as c inner join sys.types as st on st.system_type_id = c.system_type_id and st.user_type_id = c.user_type_id where c.[object_id] = object_id('[ViewTests].[expected]') select name as [ColumnName] , column_ordinal as [ColumnPosition] , system_type_name as [DataType] , [precision ]as [NumericScale] , scale as [NumericPrecision] , collation_name as [CollationName] , cast(case is_nullable when 1 then 'null' else 'not null' end as varchar(16)) as [Nullability] into #actual from sys.dm_exec_describe_first_result_set('select * from mySchema.ViewName, null, null) exec tSQLt.AssertEqualsTable '#expected', '#actual' ; end go
を、理由は非常になりますストアドプロシージャのためには、このようなテストを書きます出力がAssertEqualsTableに似ています。