Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Unit Test MSSQL 2008 & VS 2010 Aung Kyaw Myo.

Similar presentations


Presentation on theme: "Database Unit Test MSSQL 2008 & VS 2010 Aung Kyaw Myo."— Presentation transcript:

1 Database Unit Test MSSQL 2008 & VS 2010 Aung Kyaw Myo

2 Create a Script that Contains a Database Schema CREATE DATABASE SimpleUnitTestDB; GO use SimpleUnitTestDB GO PRINT N'Creating Sales...'; GO CREATE SCHEMA [Sales] AUTHORIZATION [dbo]; GO PRINT N'Creating Sales.Customer...'; GO CREATE TABLE [Sales].[Customer] ( [CustomerID] INT IDENTITY (1, 1) NOT NULL, [CustomerName] NVARCHAR (40) NOT NULL, [YTDOrders] INT NOT NULL, [YTDSales] INT NOT NULL ); GO...

3 Create a Database Project and Import a Schema SQL Server 2008 Database Project. SimpleUnitTestDB Import Script

4 Deploying to an Isolated Development Environment Properties –Deploy –Configure deployment settings for list- My isolated development environment. –Deploy Action list - Create a deployment script (.sql) and deploy to database. –Target Database Settings - Edit. –Target database name - SimpleUnitTestDB. –Deployment configuration file – Edit - Block incremental deployment if data loss might occur –Build menu - Build Solution.

5 Create Database Unit Tests Database Schema View Create Unit Tests Create a new Visual C# test project. Execute unit tests using the following data connection Deployment- select the Automatically deploy the database project before unit tests are run SimpleUnitTestDB.dbproj Debug

6 Define Test Logic uspNewCustomer - Verify that the Customer table contains one row after you run the stored procedure. uspPlaceNewOrder - For the customer who has a CustomerID of 1, place an order for $100. Verify that the YTDOrders amount for that customer is 100 and that the YTDSales amount is zero. uspFillOrder - For the customer who has a CustomerID of 1, place an order for $50. Fill that order. Verify that YTDOrders and YTDSales amounts are both 50.

7 Sales_uspNewCustomerTest Inconclusive --- Delete (x). Row Count --- Add Test Condition Properties --- Row Count --- 1 Save All

8 Sales_uspPlaceNewOrderTest Inconclusive --- Delete Scalar Value --- Add Test Condition Properties --- Expected Value --- 100 Save All

9 Sales_uspFillOrderTest Inconclusive --- Delete Scalar Value --- Add Test Condition Properties --- Expected Value --- 100 Save All

10 Run Database Unit Tests Test View --- Refresh Sales_uspNewCustomerTest- Run Selection Sales_uspFillOrderTest -> Fail Sales_uspPlaceNewOrderTest -> Pass Sales_uspShowOrderDetailsTest -> Pass

11 correct the error Schema -> -> -> ->Sales.uspFillOrder UPDATE [Sales].[Customer] SET YTDSales = YTDSales - @Delta WHERE [CustomerID] = @CustomerID UPDATE [Sales].[Customer] SET YTDSales = YTDSales + @Delta WHERE [CustomerID] = @CustomerID Build Deploy

12 RUN DELETE Script Delete from Sales.Orders dbcc checkident ( "Sales.Orders", reseed, 0) delete from Sales.Customer dbcc checkident ( "Sales.Customer", reseed, 0)

13 Q & A Thank


Download ppt "Database Unit Test MSSQL 2008 & VS 2010 Aung Kyaw Myo."

Similar presentations


Ads by Google