tSQLt - Database Unit Testing for SQL Server

Database Unit Testing for SQL Server

  • Home
  • Docs
    • Documents
    • Quick Start
    • Articles
  • Training
  • Downloads
tSQLt » Documents » Assertions » AssertObjectExists

AssertObjectExists

Syntax

tSQLt.AssertObjectExists [@objectName = ] 'object name'
                      [, [@message = ] 'message' ]

Arguments

[@objectName = ] ‘object name’
The name of a database object which you want to assert existence. @objectName is NVARCHAR(MAX) with no default.
[@message = ] ‘message’
Optional. String containing an additional failure message to be used if the object does not exist. @message is NVARCHAR(MAX) with no default.

Return Code Values

Returns 0

Error Raised

Raises a ‘failure’ error if the specified object does not exist.

Result Sets

None

Overview

AssertObjectExists checks to see if an object with the specified name exists in the database. If the object name begins with a ‘#’, indicating it is a temporary object (such as a temporary table), then tempdb is searched for the object.

Examples

Example: Using AssertObjectExists to check if an object was created
This test case uses AssertObjectExists to test that a stored procedure creates a new stored procedure based on the supplied table name.

CREATE PROC TestTemplateUtil.[test CreateTableTemplate creates an update stored procedure]
AS
BEGIN
    CREATE TABLE MyTable (i INT);

    EXEC TemplateUtil.CreateTableTemplate 'MyTable';

    EXEC tSQLt.AssertObjectExists 'UpdateMyTable';
END;

See Also

  • AssertEmptyTable
  • AssertEquals
  • AssertEqualsString
  • AssertEqualsTable
  • AssertEqualsTableSchema
  • AssertLike
  • AssertNotEquals
  • AssertObjectDoesNotExist
  • AssertObjectExists
  • AssertResultSetsHaveSameMetaData
  • Fail
Share and Enjoy:
  • FacebookFacebook
  • TwitterTwitter
  • LinkedInLinkedIn
  • RedditReddit
  • StumbleUponStumbleUpon
  • TechnoratiTechnorati
  • PrintPrint

Navigation

  • Full user guide
  • Why you should use the tSQLt framework
  • How to get more out of tSQLt
  • Join the conversation
  • Downloads
  • Articles
  • Release Notes
  • New Logo
  • Training
  • Sponsors & Contributors
  • Why you should unit test SQL Server Code
  • Documents
    • Quick Start
    • tSQLt Tutorial
    • tSQLt Keyboard Shortcuts
    • Test Creation and Execution
      • NewTestClass
      • DropClass
      • RunAll
      • Run
      • RenameClass
    • Assertions
      • AssertNotEquals
      • AssertEmptyTable
      • AssertEquals
      • AssertEqualsString
      • AssertEqualsTable
      • AssertObjectExists
      • AssertResultSetsHaveSameMetaData
      • Fail
      • AssertObjectDoesNotExist
      • AssertEqualsTableSchema
      • AssertLike
    • Expectations
      • ExpectException
      • ExpectNoException
    • Isolating Dependencies
      • ApplyConstraint
      • FakeTable
      • SpyProcedure
      • FakeFunction
      • RemoveObjectIfExists
      • ApplyTrigger
      • RemoveObject

Links

  • tSQLt on GitHub
  • tSQLt Mailing List
  • twitter hashtag (#tsqlt)
  • tSQLt tag on stackoverflow.com
  • SQL Server Community on Slack (#tsqlt)
  • #tSQLtLive on YouTube

Sponsors

sqlity.net
redgate.com

A sqlity.net llc Web Property. | ©2010 - 2020, All Rights Reserved. | Privacy Policy | Terms of Use