nanonerd
nanonerd

Reputation: 1984

Configure SQL Test with Teamcity integration

I am using SQL Test to create some unit tests in SQL Server. And I integrated with Teamcity so that on a build, it auto runs the tSQLt tests.

The issue is that we plan to create hundreds of unit tests for all our store procs. And we don't want to run all of the unit tests each time we check in code and whereby Teamcity runs a build + runs all the unit tests.

Is there a way to configure the integration build to only run the new unit tests that are checked in. Would I need to create a custom script for this? I can't seem to find a way out of the box.

Or is the practical solution to check in without Teamcity auto running the tSQLt unit tests? Thereby, just manually run the new test cases on the DEV server (after check in)? An extension of this is to run a batch nightly to run ALL the unit tests.

Upvotes: 1

Views: 1518

Answers (3)

Jon
Jon

Reputation: 583

Rather than just running the new tests each time you could use test classes to separate out any 'tier 1' tests that you want to run on every check in, from other tests that you want to run less frequently.

A test class is created using a specific schema. You could then use a SQL Compare/Source Control filter to exclude any schemas that you don't want to get tested on each commit.

That feels safer than only running the new tests. If you only run new tests then you don't know if your change has broken existing functionality.

Update: SQL CI and the Team City Plugin now let you specify any classes that you wanted to include/exclude, instead of just running tSQLt.RunAll.

Upvotes: 2

Andrew
Andrew

Reputation: 5277

I am not sure how you are creating your tsqlt results for you CI server, but if you are using

EXEC tSQLt.RunWithXmlResults 

to generate your test output, another possible option you could play around with is.

EXEC tSQLt.SetTestResultFormatter 'tsqlt.xmlresultformatter'
EXEC tSQLt.Run 'UnitTests_YourUnitTestClass'
EXEC tSQLt.SetTestResultFormatter 'tsqlt.defaultresultformatter'

Upvotes: 1

Andrew
Andrew

Reputation: 5277

Is there a particular reason that you don't want all tests to be run on the build server every time there is a check-in?

We have over 1000 tSQLt tests in the project I am currently working on and another 3000 code tests. All our tests run each time there is a check-in.

I don't use SQL Test to write my tSQLt tests anymore as I have integrated my database unit testing into my Visual Studio project. I have a T4 template that creates NUnit wrappers around my tSQLt tests and as far as my build server is concerned it is just running a set of regular NUnit tests when it runs the tSQLt unit tests. This means I can use NUnit categories etc to control what tests are run on the build server and when they should be run (i.e. every time, only during the nightly build) if I chose to.

For an example of how I do this see (https://github.com/chilli-andrew/). This may not fit your workflow, but it's worth a look to get a different perspective as to how you can work with tSQLt.

Upvotes: 5

Related Questions