michael.e.obrien

Currently, we're running our unit tests with a localtestrun.testrunconfig setup script that creates a database with 'known' contents - to be tested against. The script is specified similar to:

.\Database\UnitTest\CreateUnitTestDatabase.bat

However, when I run a build, I see no evidence in the buildlog that this script has been run.

Should I see something

What is the best method for debugging a Setup (or Cleanup) script

--

Mike



Re: Team Foundation Server - Build Automation Unit Tests - Debug localtestrun.testrunconfig Setup Script

Jason Pricket - MSFT

Hi Mike,

I would think that you would see something in the log file. How are you calling the script Is it from MSBuild directly or part of the Unit test execution If its part of the test execution, you should see something in the log files for the tests.

Thanks, Jason





Re: Team Foundation Server - Build Automation Unit Tests - Debug localtestrun.testrunconfig Setup Script

michael.e.obrien

Thanks for the reply Jason.

I'm calling the script from within the localtestrunconfig.testrunconfig - with the script name specified in the 'Setup Script' field.

The script is a BAT file that executes several sqlcmd commands that create a database, such as:

REM Create SQL Server Database

sqlcmd.exe %params1% -i %sourcepath%\Database\tables\SQLCreateUnitTestDB.sql

sqlcmd.exe %params% -i %sourcepath%\Database\tables\SQLDropTables.sql

sqlcmd.exe %params% -i %sourcepath%\Database\tables\SQLCreateTables.sql

sqlcmd.exe %params% -i %sourcepath%\Database\StoredProcedures\SQLStoredProcedures.sql

sqlcmd.exe %params% -i %sourcepath%\Database\StoredProcedures\SQLQueryStoredProcedures.sql

sqlcmd.exe %params% -i %sourcepath%\Database\StoredProcedures\SQLDataPopulate.sql

In the build output I see no mention of my BAT file, or any sqlcmd output. Should I see something

Or maybe I'm taking the wrong approach:

- Should the creation of a test database be in the unit tests

- Should the TFSBuild.proj build script call the database creation (However - the developers REALLY need the ability to run unit test against a database locally in the DesktopBuild - for obvious reasons)

- And if the Setup Script is the correct location for this type of script, is there any method for determining the success/failure of such a script, i.e., is there a return value I can inspect

Or would VS2005 for Database Professionals lend a helping hand and help automate this process

Thanks!

Mike





Re: Team Foundation Server - Build Automation Unit Tests - Debug localtestrun.testrunconfig Setup Script

Jason Pricket - MSFT

Hi Mike,

I wouldn't say the approach is wrong, but here is what I can tell you: In the <DropLocation>\TestResults directory, there should be a file with a TRX extension. That file is the log for the tests that you can open in the Test Results window in Visual Studio. If you open that file in notepad, you should see a section called "Scripts" that contains a setupScript attribute that points to your batch file.

Unfortunately, when I tested this out, I couldn't find any way to tell that the script was run successfully (even by looking at the log file). It simply shows the name of the script file. Note make sure you type in a relative path for the script file, so that when it is executed on the build machine, it can find it. If you need to determine if this script was successful, I would suggest calling it from MSBuild by overriding the BeforeTest target at the bottom of your TfsBuild.proj file. Otherwise you just have to trust that the script ran.

Thanks, Jason