How can you get a build to fail when the tests fail?

Easy unit testing for databases in SQL Server Management Studio

Moderators: JonathanWatts, David Atkinson, Anu Deshpande, Michelle Taylor, David Priddle

How can you get a build to fail when the tests fail?

Postby JackAce » Sat Jul 14, 2012 7:42 pm

I am trying to use MSBuild and SQLCMD to run my tSQLt tests as part of the build/deploy process, but when MSBuild executes the tests, the command result is always a success (even when a test fails).


Code: Select all

   <Target Name="Test">
      <Message Text="==================================================" />
      <Message Text="== Run tSQLt Tests" />
      <Message Text="==" />

      <Exec Command="&quot;$(SqlCmdPath)&quot; -Q &quot;EXEC tSQLt.RunAll&quot; -S localhost -d MyDb -E" />

      <Message Text="==================================================" />
   </Target>


Is there a way to get the sqlcmd command to fail when the tests fail?


Another question:
Can the tests produce an XML file that can be parsed and used for reporting on a CI server such as Jenkins or TeamCity?
JackAce
 
Posts: 45
Joined: Fri Jul 08, 2011 11:00 pm

Postby David Atkinson » Sat Jul 14, 2012 10:38 pm

Yes, this is possible as tSQLt can output an Ant JUnit XML Report, which can be consumed by CI tools. Rather than describe it here, I'll direct you to Dave Green's excellent article:

http://www.simple-talk.com/sql/sql-tool ... tegration/

Although the example uses TeamCity, this applies to all CI tools.

Let us know how you get on.

David Atkinson
Red Gate
David Atkinson
 
Posts: 1124
Joined: Mon Dec 05, 2005 4:54 pm
Location: Twitter: @dtabase

Postby JackAce » Sat Jul 14, 2012 11:07 pm

In case anyone else was wondering, I found the solution to the build failure problem. You can cause sqlcmd.exe to fail if you use the -b option

Code: Select all
   <Target Name="Test">
      <Message Text="==================================================" />
      <Message Text="== Run tSQLt Tests" />
      <Message Text="==" />

      <Exec Command="&quot;$(SqlCmdPath)&quot; -Q &quot;EXEC tSQLt.RunAll&quot; -S localhost -d MyDb -b -E" />

      <Message Text="==================================================" />
   </Target>
JackAce
 
Posts: 45
Joined: Fri Jul 08, 2011 11:00 pm

Postby David Atkinson » Sat Jul 14, 2012 11:16 pm

Glad you got that working.

Did you get the integration with your CI tool working using TestResults.xml?

David
David Atkinson
 
Posts: 1124
Joined: Mon Dec 05, 2005 4:54 pm
Location: Twitter: @dtabase

Re:

Postby JackAce » Sat Jul 14, 2012 11:41 pm

David Atkinson wrote:Yes, this is possible as tSQLt can output an Ant JUnit XML Report, which can be consumed by CI tools. Rather than describe it here, I'll direct you to Dave Green's excellent article:

http://www.simple-talk.com/sql/sql-tool ... tegration/



Thanks, David. I've amended my scripts.
JackAce
 
Posts: 45
Joined: Fri Jul 08, 2011 11:00 pm


Return to SQL Test

Who is online

Users browsing this forum: No registered users and 1 guest