tSQLt.FakeTable doesnt seem to work with views that have constants/derived fields

The problem is that SQL Server catches this at compile time, so the FakeTable gets never executed. That is what SetFakeViewOn was supposed to catch, however it currently does not work reliably. There is no really clean way around this right now other then putting the inserts and updates into dynamic SQL:

CREATE PROCEDURE    TestChanges.[Test Data]
AS
BEGIN
...

exec tSQLt.FakeTable 'dbo.viewWithIssues', @identity=1, @ComputedColumns=1, @Defaults=1;
EXEC('INSERT INTO dbo.viewWithIssues (clock_id, IsTerminated)'+
'VALUES  (''1111'', ''0''), (''2222'', ''1''), (''3333'', ''1'');');

...
END

Tags:

Sql

Tsqlt