W ostatnim wpisie, przedstawiłem prosty test wykonywany po stronie bazy danych. Zanim przejdę do omawiania bardziej zaawansowanych tematów, warto przyjrzeć się narzędziu SQL Test. Jest to proste narzędzie od RedGate, umożliwiające odpalenie i tworzenie testów. Zamiast np. ręcznie wywoływać “NewTestClass” czy “RunAll”, odpalamy testy tak samo jak w Visual Studio.
Po zainstalowaniu wersji trial, zobaczymy w SQL Management Studio następujące okno:
Jak widać, możemy uruchomić dowolny test. Jeśli chcemy dodać nowy test, pojawi się okno gdzie możemy podać nazwę testu oraz test fixture:
Narzędzie stworzy schema oraz szablon procedury reprezentującej test:
USE [testdb] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- Comments here are associated with the test. -- For test case examples, see: http://tsqlt.org/user-guide/tsqlt-tutorial/ ALTER PROCEDURE [divideTests].[test anotherTest] AS BEGIN --Assemble -- This section is for code that sets up the environment. It often -- contains calls to methods such as tSQLt.FakeTable and tSQLt.SpyProcedure -- along with INSERTs of relevant data. -- For more information, see http://tsqlt.org/user-guide/isolating-dependencies/ --Act -- Execute the code under test like a stored procedure, function or view -- and capture the results in variables or tables. --Assert -- Compare the expected and actual values, or call tSQLt.Fail in an IF statement. -- Available Asserts: tSQLt.AssertEquals, tSQLt.AssertEqualsString, tSQLt.AssertEqualsTable -- For a complete list, see: http://tsqlt.org/user-guide/assertions/ EXEC tSQLt.Fail 'TODO:Implement this test.' END;
Narzędzie jest bardzo proste i dość znacząco ułatwia posługiwanie się tSQLt. Moim zdaniem jednak cena zdecydowanie nie jest adekwatna to możliwości produktu.