DbFit 3.0.1 for FitNesse with Data Warehouse worked examples Presented by Chris SAUNDERS - September 2014 @chrisrsaunders
99% Presentation Presenter’s Background [2%] Audience Survey [4%] DbFit Intro [5%] Data Warehouse Intro [8%] Worked Examples [75%] Discussion [5%]
Presenter’s Background
as a professional occupation. Chris SAUNDERS a little more background… Test & Agile Practitioner One who practices testing & agile software development, as a professional occupation.
Chris SAUNDERS Originally a Systems Engineer. Spent a decade on my OE in the United Kingdom. Returned to Christchurch as a Test Manager; contracted for 5 years & now permanent. 2008 Healthcare Education Payroll Local Government Christchurch Aviation New Zealand Christchurch Auckland Wellington Palmerston North Utilities Degree Education Bachelor of Technology (Honours), Information Engineering Graduated 1997 Massey University Tauranga School & Polytechnic Education Healthcare Financial Services Power Generation Fashion IT United Kingdom Harrogate Stockport Stirling Edinburgh 1999
Audience Survey
Audience Survey Who… has used FitNesse? has used DbFit? has worked with Data Warehouses? has an understanding SQL? (Structured Query Language) What is the result of the following SQL? (Bottom table is the Fridge table) SELECT DISTINCT Drink FROM the.Fridge WHERE Temperature = 'Cold' AND Drink IN ( 'Coke' ,'Ginger Beer' ) AND ( Quality > 0 OR Quality IS NOT NULL dbo is the "default" schema for SQL Server; (database owner)
DbFit Intro
What is DbFit? DbFit is a set of fixtures which enables FIT/FitNesse tests to execute directly against a database.
What is DbFit? DbFit is a set of fixtures which enables FIT/FitNesse tests to execute directly against a database.
What is DbFit? DbFit is a set of fixtures which enables FIT/FitNesse tests to execute directly against a database.
Data Warehouse Intro Environment
Data Warehouse Environment [AdventureWorks2014] ETL [AdventureWorksDW2014] Extract Transform Load Source Data (multiple sources) Load Stage Data Warehouse Person BusinessEntityID FirstName LastName MiddleName PersonType … Person BusinessEntityID FirstName LastName MiddleName PersonType … WorkingPerson EmployeeKey BusinessEntityID FirstName LastName MiddleName SalesPersonFlag … DimPerson EmployeeKey FirstName LastName MiddleName SalesPersonFlag …
What Point to Test Source Data Warehouse Source Load Data Warehouse [AdventureWorks2014] [AdventureWorksDW2014] Extract Transform Load Source Data (multiple sources) Load Stage Data Warehouse Source Data Warehouse Source Load Data Warehouse Load Stage
What Point to Test Considered each possible test points on the threads. Source Load Stage Test Points Data Warehouse To test the whole system, one needs each thread.
Data Warehouse Intro Facts & Dims
Facts & Dimensions Fact Table Dimension Table [AdventureWorksDW2014].[dbo]. [FactResellerSales] [AdventureWorksDW2014].[dbo].[DimEmployee] Consists of the measurements, metrics or facts of a business process Calculations can be done on the measures (e.g. sum, count, min, max) Provides filtering, grouping and labelling
Worked Examples
Connection to the Database Connect command Specifying the full connection string using the full ADO.NET or JDBC connection string. or Specifying server, username, password, and database name. Connect Using File command A file contains the connection information, therefore can be environment related.
Count Data Warehouse Records table DimCustomer [AdventureWorks2014] [AdventureWorksDW2014].[dbo].[DimCustomer] ETL Known Source Data Data Warehouse Data Warehouse COUNT 18444 Check Data Warehouse table DimCustomer count record against a fixed value in FitNesse wiki page.
Count Data Warehouse Records Query command with fixed result Brittle test due to the fact this test requires updating every time test data changes as the DimCustomer table record will change. Which SQL for COUNT and why?
Count Data Warehouse Records table FactInternetSales [AdventureWorksDW2014].[dbo].[FactInternetSales] [AdventureWorks2014] ETL Known Source Data Data Warehouse COUNT Source Data Warehouse COUNT Check Data Warehouse table FactInternetSales count records against a Source data.
Count Data Warehouse Records Store Query command Compare stored queries command
Visualise SQL with Design Query in Editor
Sum Data Warehouse fields UnitPrice, table FactInternetSales [AdventureWorks2014] [AdventureWorksDW2014].[dbo].[FactInternetSales] ETL Known Source Data Data Warehouse SUM Source Data Warehouse SUM Check Data Warehouse field’s UnitPrice total sum in table FactInternetSales, against a Source data. Measures can be summed up, for all records or for a sub-set of records.
Sum Data Warehouse fields Store Query command Compare stored queries command
Check each Data Warehouse field, ListPrice in table DimProduct [AdventureWorks2014] [AdventureWorksDW2014].[dbo].[DimProduct] ETL Known Source Data Data Warehouse EXCEPT (both ways) Source Data Warehouse Check each Data Warehouse ListPrice field, in table DimProduct, against Source data. SQL’s EXCEPT function, returns any distinct values from the left query that are not also found on the right query.
Check each Data Warehouse field Limit number of errors in FitNesse. TOP 3 Return results in the same order. ORDER BY 1, 2 (or else missing records will be displayed)
Lets Change Focus
Test Database
Test Database Data Warehouse Test Database is used for: [DbFitNesseTest] [AdventureWorksDW2014] data Test Database Data Warehouse Data Warehouse Test Database is used for: Store Test data (either as a source or created from other sources) Store procedures (to be executed from FitNesse) Storing results (to compare in the future)
Test Database Report User Story Example European Internal Sales Report As an European Sales Manager, I want a Report on total “Europe Internal Sales" for each year, So that future business decisions can be made. Acceptance Criteria : 1. To include all available years 2. Only 3 countries; France, UK & Germany 3. … Year France Germany UnitedKingdom 2014 $0.00 2013 $1,578,511.80 $1,761,876.36 $2,124,007.29 2012 $648,065.54 $608,657.98 $712,700.96 2011 $410,845.33 $520,500.16 $550,591.22 2010 $3,399.99 $699.10
Test Database Data Warehouse Create a table with expected results. [DbFitNesseTest] [AdventureWorksDW2014] data Test Database Data Warehouse Data Warehouse Create a table with expected results.
Create Expected Results Table Execute command Commit command Create a table and commit to database.
Truncate Expected Results Table Inspect Table command Truncate table and commit to database. Inspect Table to confirm it’s truncated (does not Pass or Fail).
Insert into Expected Results Table Insert command Insert data into table and commit to database.
Count Data Warehouse Records Store Query command
Count Data Warehouse Records Compare Stored Queries command Data 0.00 Rounding
Count Data Warehouse Records Compare Stored Queries command
Drop Expected Results Table Drop table and commit to database.
Other Commands
Other Commands Update command Execute Procedure command Update command similar to insert command. Execute Procedure will executes a stored procedure or function for each row of data table and will bind input/output parameters to columns of the data table.
Thank you
DbFit 3.0.1 for FitNesse with Data Warehouse worked examples Adventure Works 2014 Sample Databases http://msftdbprodsamples.codeplex.com/releases/view/125550 Microsoft SQL Server 2014 Express http://msdn.microsoft.com/en-us/evalcenter/dn434042.aspx Poor Man's T-SQL Formatter http://www.architectshack.com/PoorMansTSqlFormatter.ashx DbFit examples http://www.testrun.co.nz/presentations.html (place under FitNesseRoot\DbFit\AcceptanceTests\DotNetTests) DbFit 3.0.1 for FitNesse with Data Warehouse worked examples Presented by Chris SAUNDERS - September 2014 @chrisrsaunders