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

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

Navigation

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