How to create unit test for SQL in VS 2017

Install SQL Server Data Tools

Adding SQL Server Data Tools
Adding SQL Server Data Tools.

Add new unit test project to the solution

Adding new unit test project to solution
Adding new unit test project to solution.

Add SQL Server database project to the solution

Adding SQL Server database project
Adding SQL Server database project.

Import database

Import database
Import database.
Import database wizard
Import database wizard.

Create unit test

Select stored procedure or function you want to test in Solution Explorer and right click on it. Add new unit test by the Wizard.

Creating SQL unit test
Creating SQL unit test.
Unit test wizard
Unit test wizard.

Read more

SQL Server Unit Testing in Visual Studio

Getting Started with SQL Server Database Unit Testing in SSDT

How to install and use GTest on Ubuntu

Install GTest on Ubuntu

sudo apt-get install libgtest-dev
sudo apt-get install cmake # install cmake
cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make

# copy or symlink libgtest.a and libgtest_main.a to your /usr/lib folder
sudo cp *.a /usr/lib

Create CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

# Link runTests with what we want to test and the GTest and pthread library
add_executable(runTests tests.cpp)
target_link_libraries(runTests ${GTEST_LIBRARIES} pthread)

Example

#include "../libril-gto-sqn/at_tok.c"
#include "../libril-gto-sqn/ril-main-gen.c"

#include <gtest/gtest.h>

class test_class {
    public:
        int test_method(int a, int b) {
        return a + b;
    }
};

TEST( test_class_tests, test_case )
{
    test_class test_object;

    ASSERT_EQ( test_object.test_method(2, 2), 5 );
}

int main(int argc, char **argv) {
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

Make and run tests

cmake CMakeLists.txt
make
./runTests

Getting started with Google Test (GTest) on Ubuntu

How to install and use BOOST on Ubuntu

Installation

sudo apt-get install libboost-all-dev

or

sudo aptitude install libboost-all-dev

viewing list of packages

aptitude search boost

Example

#define BOOST_TEST_MODULE test_boost
#define BOOST_TEST_NO_MAIN
#define BOOST_TEST_ALTERNATIVE_INIT_API
#include <boost/test/included/unit_test.hpp>
#include 

class test_class {
    public:
        int test_method(int a, int b) {
            return a + b;
        }
};

BOOST_AUTO_TEST_CASE( test_case )
{
    test_class test_object;

    BOOST_CHECK( test_object.test_method(2, 2) == 5 );
}

int main(int argc, char* argv[], char* envp[])
{
    return boost::unit_test::unit_test_main(init_unit_test, argc, argv);
}

Building example

g++ test_boost.cpp -o test_boost -lstdc++ -lboost_unit_test_framework

Running example

./test_boost

Running results

Running 1 test case...
test_boost.cpp(19): error in "test_case": 
check test_object.test_method(2, 2) == 5 failed

*** 1 failure detected in test suite "test_boost"

Customizing the module’s entry point