tSQLt - Database Unit Testing for SQL Server

Database Unit Testing for SQL Server

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

AssertObjectDoesNotExist

Syntax

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

Arguments

[@objectName = ] ‘object name’
The name of a database object which you want to assert non-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 exist.

Result Sets

None

Overview

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

Examples

Example: Using AssertObjectDoesNotExists to check if an object was dropped
This test case uses AssertObjectDoesNotExists to test that a stored procedure drops another stored procedure based on the supplied name.

CREATE PROC TestTemplateUtil.[test DropProcedure drops a stored procedure]
AS
BEGIN
    EXEC('CREATE PROC dbo.MyProcedure AS RETURN 0;');

    EXEC TemplateUtil.DropProcedure 'dbo.MyProcedure';

    EXEC tSQLt.AssertObjectDoesNotExists 'dbo.MyProcedure';
END;

See Also

  • AssertEmptyTable
  • AssertEquals
  • AssertEqualsString
  • AssertEqualsTable
  • AssertEqualsTableSchema
  • AssertLike
  • AssertNotEquals
  • AssertObjectDoesNotExist
  • AssertObjectExists
  • AssertResultSetsHaveSameMetaData
  • Fail

Since

V1.0.5325.27056

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