Can I integrate Redgate SQL Test directly with teamcity to get code coverage

125 Views Asked by At

I have purchased Redgate SQL Test, I need to integrate same with Teamcity.

Can i achieve it without any other licensed softwares from Redgate.

2

There are 2 best solutions below

0
On

tSQLt is the test framework that SQLTest is using. It is open-source, independent of Redgate, and integrates nicely with Teamcity. In fact, I used to run the CI Pipeline for tSQLt itself on Teamcity in the past.

Search for "tSQLt Teamcity" in your favorite search engine. You can also use Using SQL Test Database Unit Testing with TeamCity Continuous Integration by Dave Green as your starting point.

But to answer your question: You do not need other paid tools to make this work.

(Note: That article above was written before SQL Cover. SQL Cover, like tSQLt, is open source, and it too can be used without SQL Test or other Redgate tools. (See for example this article by Ed himself.) There's some evidence that people have done it, like this tweet by David from Redgate, but just now I wasn't able to find any complete documentation.)

0
On

The following PowerShell code shows how to achieve this with Redgate's SQL Change Automation driving the tests (taken from the SCA documentation). Where it says "Any testing process that exercises the code can be used instead", you can replace this line with the PowerShell statements necessary to execute tSQLt.RunAll directly.

# If running your PowerShell script from a build tool, pass in these variables as parameters
$server='yourServer\instance'
$database='yourDatabase'
 
Add-Type -Path .\SQLCover.dll
$connectionString = "server=$server;initial catalog=$database;integrated security=sspi"
$coverage = new-object SQLCover.CodeCoverage($connectionString, $database, $true, $false)
 
# This starts SQLCover. It uses XEvents to monitor activity on the database.
$coverage.Start()
 
# Between the Start and Stop, the tSQLt tests are run. 
# Any testing process that exercises the code (for example, NUnit, Selenium) can be used instead.
$testResults = $connectionString | Invoke-DatabaseTests 
 
# We stop SQLCover now that we've run our tests.
$coverageResults = $coverage.Stop()
 
# Generate a basic single-page code coverage report
$coverageResults.Html() | Out-File SQLCoverResults.html