Running batch Cleanup scripts
-
Wednesday, September 30, 2009 3:19 PM
I just atarted using VSTS2008 test edition version and I am not familiar with running a clean scripts. I would like to attach a cleanup script to the .testrunconfig but I am not sure what the required syntax for the script file is. Could someone give me am example of the syntax required for the script file if for example I was using the Northwind database and wanted to delete a record from the Norhwind databse Employees table where the LastName = "Davolio".
Thanks
Answers
-
Thursday, October 01, 2009 3:34 PMModerator
You can run batch files or executables as a setup or cleanup script and there are a few environment variables that are set in the process for you. The easiest way to get those variables is to write a batch file that does a set > env.txt and then run that as part of a setup or cleanup script.
As far as your scenario is concerned, I think the proper place for that would be in the cleanup method in a unit test.
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testcleanupattribute(VS.80).aspx
There you can just write your code in whatever language you are using and you have access to all of the .NET libraries.- Marked As Answer by ChrispatMicrosoft Employee, Moderator Thursday, October 01, 2009 3:35 PM
-
Friday, October 02, 2009 8:12 AMModerator
Hello,
Now that you want to utilize setup script to achieve your goal. I did some tests with it on my machine and it worked find.
1. Utilize this command 'sqlcmd' which is a Microsoft Win32 command prompt utility for ad hoc, interactive execution of Transact-SQL statements and scripts and for automating Transact-SQL scripting tasks. Here we create two files. One is .sql file which specify the related t-sql command, the other one is .bat file which connect to an instance and specify input. The content of the two files in my case are like this:
t.sql
use test; -- specify the database
GO
delete from [test].[dbo].[table1]; -- execute the command
GO
t.bat
sqlcmd -S <ComputerName> -i t.sql
2. Go to the .testrunconfig file, click the 'Setup and Cleanup Scripts' tab, specify the setup/cleanup script to the file 't.bat', click the 'Deployment' tab and add the two files to deploy.
3. Click 'Apply' and 'Close'
More detailed information about the syntax of sqlcmd, you can refer to this article:
http://msdn.microsoft.com/en-us/library/ms180944.aspx
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Send us any feedback you have about the help from MSFT at EMAIL GONE.- Proposed As Answer by Edwer FangModerator Tuesday, October 06, 2009 7:35 AM
- Marked As Answer by Edwer FangModerator Wednesday, October 14, 2009 7:30 AM
All Replies
-
Thursday, October 01, 2009 3:34 PMModerator
You can run batch files or executables as a setup or cleanup script and there are a few environment variables that are set in the process for you. The easiest way to get those variables is to write a batch file that does a set > env.txt and then run that as part of a setup or cleanup script.
As far as your scenario is concerned, I think the proper place for that would be in the cleanup method in a unit test.
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testcleanupattribute(VS.80).aspx
There you can just write your code in whatever language you are using and you have access to all of the .NET libraries.- Marked As Answer by ChrispatMicrosoft Employee, Moderator Thursday, October 01, 2009 3:35 PM
-
Thursday, October 01, 2009 7:44 PMChris,
Thanks for the reply. I am usuing VSTS 2008 Test edition in order to test an asp.net application written in VB with a sql server database. As you suggested I would like to add a cleanup method to my unit test in order to remove the test data.
Could you show me or point me to a more detailed example of using setup or cleanup script which shows to make the SQL database connection in order to delete the test data.
Thanks,
JFF -
Friday, October 02, 2009 8:12 AMModerator
Hello,
Now that you want to utilize setup script to achieve your goal. I did some tests with it on my machine and it worked find.
1. Utilize this command 'sqlcmd' which is a Microsoft Win32 command prompt utility for ad hoc, interactive execution of Transact-SQL statements and scripts and for automating Transact-SQL scripting tasks. Here we create two files. One is .sql file which specify the related t-sql command, the other one is .bat file which connect to an instance and specify input. The content of the two files in my case are like this:
t.sql
use test; -- specify the database
GO
delete from [test].[dbo].[table1]; -- execute the command
GO
t.bat
sqlcmd -S <ComputerName> -i t.sql
2. Go to the .testrunconfig file, click the 'Setup and Cleanup Scripts' tab, specify the setup/cleanup script to the file 't.bat', click the 'Deployment' tab and add the two files to deploy.
3. Click 'Apply' and 'Close'
More detailed information about the syntax of sqlcmd, you can refer to this article:
http://msdn.microsoft.com/en-us/library/ms180944.aspx
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Send us any feedback you have about the help from MSFT at EMAIL GONE.- Proposed As Answer by Edwer FangModerator Tuesday, October 06, 2009 7:35 AM
- Marked As Answer by Edwer FangModerator Wednesday, October 14, 2009 7:30 AM
-
Monday, October 05, 2009 2:00 PMHi Ed,
I am actually doing my initial testing locally using 2005 SQL Express database. Are you aware of any limitations as far as using sqlcmd on the Express Edition is concerned?
Thanks for your help,
Joe -
Tuesday, October 06, 2009 7:34 AMModeratorHello Joe,
I have SQL SERVER 2008 Enterprise edition on my machine and everything goes fine. As far as I am concerned, sqlcmd works fine with SQL EXPRESS 2005, you can try manually double-clicking the .bat file as mentioned above to see if the SQL Command has been executed or not. If you any questions about SQL Server Express, you can post on the SQL Server Express Forum.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Send us any feedback you have about the help from MSFT at EMAIL GONE.