Question

I am trying to integrate tSQLt / SQLTest with CruiseControl.NET My tests are running and I've written xsl files to display the results but I need to know how to mark the build as failed if any tests fail.

My CCNet exec is:

<exec executable="$(sqlCmdPath)">
    <description>Run Unit Tests</description>
    <buildArgs>-E -d MyDatabase 
       -i "\CruiseControlProjects\Configuration\CI_SQL\RunTests.sql"
    </buildArgs>
    <baseDirectory>\Artifacts\MyDatabase</baseDirectory>
    <successExitCodes>0,63</successExitCodes>
</exec>

RunTests.sql:

IF EXISTS (SELECT * FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'[tSQLt].[RunAll]')
AND TYPE IN (N'P',N'PC'))
BEGIN
EXECUTE [tSQLt].[RunAll]
END

The tests are run and I have a subsequent task which produces the results in xml that are then merged into the build log:

<exec executable="$(sqlCmdPath)">
    <description>Get Unit Tests</description>
    <buildArgs>-E -b -d MyDatabase -h-1 -y0 -I 
       -i "\CruiseControlProjects\Configuration\CI_SQL\GetTestResults.sql" 
       -o "\CruiseControlProjects\Configuration\CI_SQL\Results\TestResults.xml"
    </buildArgs>
    <baseDirectory>\Artifacts\MDatabase</baseDirectory>
    <successExitCodes>0,63</successExitCodes>
</exec>

So how do I get the overall build to fail?

Was it helpful?

Solution

If you use the -b parameter to sqlcmd, you should find that it will throw an error with a non-zero code when the batch fails (which will happen if tSQLt fails at least one test).

However, I have one potential suggestion to explore. If you can load the XML file within Cruise Control, then the tests can be loaded in as the XML file is in the same format as an nUnit test output file. (Note - I've used this method on TeamCity and Jenkins, but not tried with Cruise Control). This will treat the tests as tests rather than an 'all-or-nothing' approach, and enabling you to track which tests fail repeatedly.

Hope that helps,

Dave.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top