Database tests

NovaSql runs tests that live in the database as stored procedures. Tests in the header opens the test explorer; it works with the connection of the active tab.

Tests are locked in the demo version.

What a test is

Every procedure whose name starts with the prefix (default test_) is a test. The prefix can be changed at the bottom of the panel under Prefix:.

  • Passed: the procedure runs without an error.
  • Failed: the procedure raises an error, for example with THROW or RAISERROR at severity 11 or above. The error message is shown next to the test.

Every test runs in its own transaction, which is rolled back afterwards. A test may therefore insert, change and delete data: the database looks the same afterwards as before.

An example

CREATE PROCEDURE dbo.test_create_customer_sets_created_date
AS
BEGIN
    INSERT INTO dbo.Customers (Name) VALUES (N'Test customer');

    IF NOT EXISTS (SELECT 1 FROM dbo.Customers
                   WHERE Name = N'Test customer' AND Created IS NOT NULL)
        THROW 50000, N'Created date was not set', 1;
END

Running tests

  • Discover tests finds every test procedure in the database.
  • Run all, Run selected or Re-run failed.
  • Cancel stops a running pass.
  • Reset results sets every test back to Not run.

At the top the list can be filtered by Passed, Failed and Not run. Every test shows its duration.

Limits

Anything that takes effect outside the transaction is not rolled back: a COMMIT inside the test procedure itself, changes on a linked server, or mail that was sent. So write tests without a COMMIT of their own.