2017-04-11 2 views
0

많은 수의 열을 반환하는 쿼리에서 메타 데이터를 확인하려면 tSQLt AssertResultSetsHaveSameMetaData을 사용하려고합니다.tSQLt AssertResultSetsHaveSameMetaData SQLTest에서 잘린 응답 메시지

'예상 /하지만 오류'세부 정보가 잘린 메시지가 잘리지 않으므로 두 가지 정보를 잘못 볼 수는 없습니다. 메시지를 잘라내어 (예를 들어 파일로) 출력하지 않을 수 있습니까?

답변

0

테스트를 실행하기 전에 EXEC [tSQLt].[XmlResultFormatter];을 시도해 볼 수 있습니다. 이것은 "서버 빌드"시나리오에서 사용하기위한 것이지만 SSMS에서 더 많은 출력을 보여주기 위해 서비스를받을 수 있습니다.

1

실제로 테스트하고있는 내용에 따라 다릅니다. 나는 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과 비슷합니다.