npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sql-server-test-runner

v2.3.0

Published

A simple test runner for SQL Server databases that executes .sql scripts containing sp unit tests using sqlcmd and reports failed sp executions.

Readme

sql-server-test-runner

A lightweight SQL script test runner powered by sqlcmd.

Write your unit tests as stored procedures inside individual .sql files, ask sstr to run them against an ad-hoc restored backup of your database, and get a clean pass/fail report in your terminal or CI pipeline.

  • Works as a CLI (sstr) and as a Node.js module.
  • Discovers test files with a regex (testRegex).
  • Supports per-environment config files (sstr.config.{env}.json).
  • Provides assertion stored procedures (Assert.*) to use in your unit test procedures.
  • Creates, backs up, restores, and drops the test database automatically.
  • Reports per-file and per-procedure results, with detailed error messages.

In Short:

  • CLI: sstr
  • Config file: sstr.config.json

Requirements

  • Node.js >= 22 (LTS). Node 18 is end-of-life and is not supported.
  • sqlcmd available on PATH (comes with SQL Server Command Line Utilities / SSMS / mssql-tools)

Installation

npm install -g sql-server-test-runner

Or as a dev dependency:

npm install --save-dev sql-server-test-runner

Quick Start

  1. Create sstr.config.json in your project root:
sstr init

output:

{
  "connection": {
    "server": "localhost",
    "trustedConnection": true,
    "trustServerCertificate": true
  },
  "loginTimeout": 15,
  "queryTimeout": 180,
  "backupPath": "C:\\sstr-backups",
  "cleanupBackup": true,
  "testRegex": "(tests/.*|(\\.|/)(test|spec))\\.sql$",
  "testMatch": "^test_",
  "testSchema": "sstr",
  "assertSchema": "Assert",
  "scripts": {
    "warmUp": "tests/warmup.sql",
    "coolDown": "tests/cooldown.sql"
  },
  "sqlCmdOptions": {
    "enableQuotedIdentifiers": true
  }
}
  1. Create tests/sum.test.sql:
create or alter proc test_sum_should_return_summation_of_values
as
begin
    set nocount on;

    declare @a int = 10;
    declare @b int = 20;

    declare @result int = dbo.Sum(@a, @b);
    
    exec Assert.Equals @result, 30;
end
go
  1. Run:
sstr run

You should see:

==============================================
 Test Report
==============================================
Test script files: 1

Per-file details:
  - C:/project/tests/sum.test.sql [PASS]
      procedures: 1, pass: 1, fail: 0
----------------------------------------------
Total: 1, pass: 1, fail: 0
==============================================

The one-line install

The dependency on sqlcmd is not a burden. Microsoft ships a standalone, cross-platform sqlcmd (Go) that installs in seconds:

# Windows
winget install sqlcmd

# macOS
brew install sqlcmd

# Ubuntu / Debian
apt-get install sqlcmd

No SQL Server installation required on the machine you use sstr. No Visual Studio. No CLR.


Why Not tSQLt?

tSQLt is the de facto standard for SQL Server unit testing, and it is excellent. It is mature, feature-rich, and battle-tested. If your team already lives in the Visual Studio / SSDT ecosystem and needs advanced features like table mocking, tSQLt is a great choice.

But "standard" does not mean "the only reasonable choice." If you are a Node.js developer who just wants to write SQL tests without leaving your comfort zone, tSQLt may feel heavy. Here is where sstr genuinely differs.

The honest comparison

| Concern | tSQLt | sstr | |---|---|---| | Installation | Requires enabling CLR, running PrepareServer.sql with SA permissions, and installing the framework into each development database. | npm install -g sql-server-test-runner plus a one-line sqlcmd install. Nothing to enable on the server. | | Server-side configuration | CLR must be enabled. In some environments (Azure SQL, hardened servers) this is restricted or forbidden. | Zero server-side configuration. Only sqlcmd is required on the client. | | Ecosystem | Deeply tied to Visual Studio, SSDT, and the .NET tooling ecosystem. | Pure Node.js. Install it, import it, or run it from any terminal. | | Learning curve | Requires understanding CLR, test classes, FakeTable, and tSQLt conventions. | If you know T-SQL and npm, you already know how to use it. Write a stored procedure, run sstr run. | | Table mocking | Full FakeTable support, which is powerful for isolating dependencies. | Intentionally not included. You provide a clean test database, seed data inside your test, and the tool rolls everything back. | | Set comparison | AssertEqualsTable for comparing result sets. | Not included. Use EXCEPT in your test if you need it. | | Transaction isolation | Automatic per-test rollback. | Automatic per-test rollback. Opt out per test with transaction: false or globally with --no-transaction. | | Per-test configuration | Possible via tSQLt conventions, but not a first-class feature. | JSON file next to each test file: transaction, logExecution, skip, timeout, preScript, postScript, throws. | | Expected failures | Possible but not a dedicated feature. | throws: true (any error) or throws: <number> (specific SQL Server error number). | | Per-test setup/teardown | Possible via tSQLt helpers. | preScript / postScript in the per-test JSON file. | | Multiple test schemas | Not a first-class concept. | testSchema accepts a comma-separated list. The sstr schema is always treated as a test schema. | | Built-in assertion set | Full tSQLt assertion set. | 14 value assertions (Equals, IsTrue, IsBetween, ...). For schema-object checks, use DbMold. | | Reports | Possible via custom scripts. | Built-in console, json, and junit reports. | | CI integration | Possible, often via custom scripts. | --report-type junit drops straight into GitHub Actions, GitLab CI, Azure Pipelines, and any JUnit-compatible dashboard. | | Connection check | Not a dedicated command. | sstr connect verifies the connection and prints server info. | | Cleanup | Manual. | sstr clean removes leftover databases and .bak files, with --dry-run. | | Dependencies | CLR, SSDT (usually), Visual Studio (usually). | sqlcmd only. |

The philosophical difference

tSQLt tries to give you everything. That is its strength and its weight.

sstr tries to give you just enough. You bring a clean test database (or let the tool create one), write a plain T-SQL stored procedure that calls Assert.Equals, and you are done. No mocking framework, no CLR, no Visual Studio. If your test needs data, insert it inside the procedure. When the test finishes, the transaction rolls back and the database is clean for the next test.

This works because of a simple trade-off: you provide a controlled environment, and the tool stays out of your way.

When you should still choose tSQLt

Be honest with yourself. If any of the following apply, use tSQLt instead:

  • Your team already uses SSDT and Visual Studio for database development.
  • You need FakeTable to test procedures against complex schemas with many foreign keys and constraints.
  • You rely on AssertEqualsTable for set-based result comparisons.
  • Your organization requires a proven, industry-standard framework with a long track record.

sstr is not trying to replace tSQLt in those scenarios. It is trying to serve the developer who would otherwise write no SQL tests at all because the barrier felt too high.

Documentation


Related projects

  • DbMold — idempotent, forward-only schema manipulation for SQL Server. If you need table_exists, column_exists, default_exists, record_exists, or idempotent DDL helpers, install DbMold alongside sstr. sstr focuses on test assertions; DbMold focuses on general-purpose SQL helpers.

License

MIT