0

Is it possible to run SQL unit tests during the build process in VSTS (which would ideally cause the build to fail if any tests fail)? Or, can I only run tests after build/deploy on the drop server's SQL Server?

Thanks!

5
  • Can you provide more info about your Sql unit tests? Unit tests usually don't hit a 3rd party (like a database). That's an integration test. Anyways, do you have a bunch of tests in your repository, first? Give us some more info please about how you have things setup, right now.
    – Pure.Krome
    Sep 12, 2016 at 4:34
  • @Pure.Krome Right now the setup is that in my solution, two of my projects consist of SQL tests (stored procedures that are tests). Then, I have two other projects that correspond to the two SQL test projects, and these projects consist of .cs classes that execute the tSQLt tests. I am unsure where to go from here: do I execute the .sql tests or the .cs classes that call the tests? In either case, would I need to run on SQL Server somehow during the build process? Sep 12, 2016 at 17:49
  • Post a picture, please (update your post). The bit: "two of my projects consist of SQL tests (stored procedures that are tests)" really scares me, so show us a picture first so I don't make poor assumptions about your text, above.
    – Pure.Krome
    Sep 13, 2016 at 5:26
  • 1
    Pure.Krome don't get too excited about "stored procedures as tests" - this is how the tSQLt framework works so makes perfect sense. I don't have the details to hand but the other alternative would be to use sqlcmd or powershell to execute tSQLt.RunAll to run all unit tests (from within the TfsBuild process). tSQLt.RunAll will generate a SQL exception if any tests fail or error. You could even use tSQLt.XmlResultFormatter to extract the results of individual tests. Sep 13, 2016 at 15:31
  • the c# projects that execute the tSQLt tests: are these "test projects" in the sense that you can execute them with mstest/vstest, or in the VS test runner? If so, you're good to go, all this works the same way in VSTS. Sep 22, 2016 at 20:02

1 Answer 1

0

You need to deploy the objects under test somewhere before they can be exercised, whether this is by SQL Server Unit Tests (of the Visual Studio variety) or by tsqlt tests.

As you point out, one possible location is after the artefacts have gone to the drop server, but there are a couple more possibilities:

  • The localdb instance provided in VSTS
  • A SQL Azure database
  • Some other database; Azure VMs, AWS, maybe even on-prem!

Update: CLR doesn't work in SQL Azure any more, and this is required for tSQLt

1
  • UPDATE: Azure SQL does now support CLR and tSQLt can be run, however, sp_configure and CONFIGURE/RECONFIGURE are not supported, so you have to remove/comment those from the tSQLt install. Mar 21, 2019 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.