tSQLt-org / tSQLt

The official tSQLt repository. (Download at: http://tSQLt.org/downloads )
http://tSQLt.org
416 stars 104 forks source link

Question about tSQLt.Fail design #203

Open ay-azara opened 4 months ago

ay-azara commented 4 months ago

Hey, this isn't really an issue and I think I already know the answer but figured I'd ask anyway.

The code below fails if you call something like tsqlt.AssertEquals(0, 1, 'Fail message') outside the test runner. I ran into this while debugging some tests interactively; create some temp code, select code, execute code type stuff.

https://github.com/tSQLt-org/tSQLt/blob/60a1cc81a1bc4c220b57b63044eb289cb6ee6606/Source/tSQLt.Fail.ssp.sql#L40-L51

The table is created by tSQLt.Private_RunTest_TestExecution so I assume the expectation is that you'd never run tsqlt procs without the test runner but would there be a problem if tsqlt.Fail checked for the table and created it if it didn't exist as a fallback? It'd be cool if RAISERROR included the failure message but again my usage is outside the norm so I'm probably barking up the wrong tree :)

   IF OBJECT_ID(N'tempdb..#TestMessage') IS NULL
    CREATE TABLE #TestMessage(Msg NVARCHAR(MAX));