Giter Site home page Giter Site logo

pstsqlttestgenerator's Introduction

Master Branch Development Branch
Build status Build status

PStSQLtTestGenerator

What does it do

Unit testing is fairly new to databases and more and more companies are implementing it into their development process. The downside is that the existing objects do not have any unit tests yet.

That's where this PowerShell module comes in. This module makes it possible for you to generate basic unit tests for database objects.

Tests like:

  • Database Collation
  • Objects Existence
  • Function Parameters
  • Stored Procedure Parameters
  • Table Columns
  • View Columns

How to install

Run the following to install the module from the PowerShell Gallery (to install on a server or for all users, remove the -Scope parameter and run in an elevated session):

Install-Module PStSQLtTestGenerator -Scope CurrentUser

How to run the module

The main command to get all the tests is Invoke-PSTGTestGenerator.

To get all the tests run the following command:

Invoke-PSTGTestGenerator -SqlInstance [yourinstance] -Database [yourdatabase] -OutputPath [testfolder]

That's all that is to it. The tests will all be written to the designated folder. You can then copy these to your SSDT project or run the scripts to create the the tests in your database

For more help and information about any particular command, run the Get-Help command, i.e.:

Get-Help Invoke-PSTGTestGenerator

How does it work

The modules works by iterating through database objects and create tests according to the type of object.

Based on a specific template for each test, it will create a ".sql" for each test with the correct content.

For instance, all the functions, stored procedures, tables and views will have a test to check if they exists the next time the tSQLt unit test runs.

Let's take the table "dbo.Customer". This table would get a test called "test If table dbo.Customer exists Expect Success.sql". This test file would contain content similar to this:

/*
Description:
Test if the table dbo.Customer exists

Changes:
Date		Who					Notes
----------	---					--------------------------------------------------------------
9/18/2019	sstad				Initial test
*/
CREATE PROCEDURE [TestBasic].[test If table dbo.Customer exists Expect Success]
AS
BEGIN
    SET NOCOUNT ON;

    ----- ASSERT -------------------------------------------------
    EXEC tSQLt.AssertObjectExists @ObjectName = N'dbo.Customer';
END;

pstsqlttestgenerator's People

Contributors

sanderstad avatar mverbaas avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.