tSQLt - Database Unit Testing for SQL Server

Database Unit Testing for SQL Server

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

AssertEqualsString

Syntax

tSQLt.AssertEqualsString [@expected = ] expected value
                       , [@actual = ] actual value
                      [, [@message = ] 'message' ]

Arguments

[@expected = ] expected value
The expected value for the test. @expected is NVARCHAR(MAX) with no default.
[@actual = ] actual value
The actual value resulting from processing during the test. @actual is NVARCHAR(MAX) with no default.
[@message = ] ‘message’
Optional. String containing an additional failure message to be used if the expected and actual values are not equal. @message is NVARCHAR(MAX) with no default.

Return Code Values

Returns 0

Error Raised

Raises a ‘failure’ error if expected and actual are not equal.

Result Sets

None

Overview

AssertEqualsString compares two string values for equality. If they are not equal, the test case is failed; otherwise, AssertEqualsString does not affect test processing. For the purposes of AssertEqualsString, NULL is considered equal to NULL. Any non-NULL value is considered not equal to NULL.

Examples

Example: AssertEqualsString to check the results of a function
This test case uses AssertEqualsString to compare the return result of a function with an expected value. The function formats a first and last name into a standard string for display.

CREATE PROC TestPerson.[test FormatName concatenates names correctly]
AS
BEGIN
    DECLARE @expected NVARCHAR(MAX); SET @expected = 'Smith, John';
    DECLARE @actual NVARCHAR(MAX);

    SELECT @actual = person.FormatName('John', 'Smith');

    EXEC tSQLt.AssertEqualsString @expected, @actual;
END;

Example: A variety of the possibilities of AssertEqualsString

The examples below show what to expect from AssertEqualsString when called with different values.

EXEC tSQLt.AssertEqualsString 'hello', 'hello'; -- pass
EXEC tSQLt.AssertEqualsString N'goodbye', N'goodbye'; -- pass
EXEC tSQLt.AssertEqualsString 'hello', N'hello'; - pass (values are compared as NVARCHAR(MAX)

EXEC tSQLt.AssertEqualsString 'hello', NULL; -- fail
EXEC tSQLt.AssertEqualsString NULL, 'hello'; -- fail
EXEC tSQLt.AssertEqualsString NULL, NULL; -- pass

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