the what, why and how of unit testing with sql server

29
The What, Why and How of Unit Testing Annette Allen

Upload: techexeter

Post on 16-Apr-2017

117 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: The what, why and how of Unit Testing with SQL Server

The What, Why and How of Unit Testing

Annette Allen

Page 2: The what, why and how of Unit Testing with SQL Server

Who is Annette Allen

DBA/Dev for 14 years Joint Chapter Leader of SQL South West based in the South

West of England Event organiser Friend of Red Gate UK Regional Mentor

Page 3: The what, why and how of Unit Testing with SQL Server

Agenda

Why do we test? What we test? How do we test?

Page 4: The what, why and how of Unit Testing with SQL Server

Why

Page 5: The what, why and how of Unit Testing with SQL Server

Why get requirements?

Requirements

Acceptance Criteria

Test List

Page 6: The what, why and how of Unit Testing with SQL Server

How do we get requirements?

Conversation Email Backlog

Page 7: The what, why and how of Unit Testing with SQL Server

I want . . . . .

Page 8: The what, why and how of Unit Testing with SQL Server
Page 9: The what, why and how of Unit Testing with SQL Server

Speak to stakeholder

I want. . . . . A car that is cheap, young and practical

Page 10: The what, why and how of Unit Testing with SQL Server
Page 11: The what, why and how of Unit Testing with SQL Server
Page 12: The what, why and how of Unit Testing with SQL Server

Requirements

I want: “A list of cars that are cheap, young and practical”

Page 13: The what, why and how of Unit Testing with SQL Server

Requirements

“I need a car that is under 5 years old, costs less than £10k can do more than 40mpg and can take 4 people”.

Page 14: The what, why and how of Unit Testing with SQL Server

Tests

1. Price is under £10k

2. Age is under 5

3. Seats >= 4

4. Fuel economy > 40 mpg

Page 15: The what, why and how of Unit Testing with SQL Server

Acceptance Criteria

The car must be under 5 years old The car must cost less than £10k The car must have at least 4 seats It must do at least 40 mpg

Page 16: The what, why and how of Unit Testing with SQL Server

What have we learned?

Ask questions Ensure no misunderstanding

Confirm requirements Measurable Quantifiable

Page 17: The what, why and how of Unit Testing with SQL Server

Requirements gathering

I need a report showing current, good applicants.

Page 18: The what, why and how of Unit Testing with SQL Server

Requirements gathering

Applicant = flag in system Current = applied for intake to start September 2016 Good = must have at least 3 predicted A Levels at AAA, AAB or

ABB

Page 19: The what, why and how of Unit Testing with SQL Server

Tests

Applicant = Yes Start Date > 1 September 2016 Predicted grade tests x 4:

AAA is included AAB is included ABB is included BBB is excluded

Page 20: The what, why and how of Unit Testing with SQL Server

Anything else?

Page 21: The what, why and how of Unit Testing with SQL Server

How do we test

tSQLt Community tool Licence free

Redgate SQL Test Fully licenced and supported product Part of the Developer suite

Page 22: The what, why and how of Unit Testing with SQL Server

Using tSQLt

Test Class All tests must start with the word ‘test’ Names should define what’s being tested Tests should test 1 thing and 1 thing only

Page 23: The what, why and how of Unit Testing with SQL Server

Test Object Hierarchy

GetListOfPracticalCars

GetListOfPracticalCars

Database object

Test Class

GetListOfPracticalCars.[TestAge] Test object

GetListOfPracticalCars.[TestPrice] Test object

Page 24: The what, why and how of Unit Testing with SQL Server

How does this work?

Fake everything Functions Data All other objects relied upon by the object tested

Page 25: The what, why and how of Unit Testing with SQL Server

What is Test Driven Development

Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards. Kent Beck, who is credited with having developed or 'rediscovered'[1] the technique, stated in 2003 that TDD encourages simple designs and inspires confidence.[2]

Taken from Wikipedia – Nov 2015

Page 26: The what, why and how of Unit Testing with SQL Server

Demo

Page 27: The what, why and how of Unit Testing with SQL Server

Downloads

http://tsqlt.org/downloads/ https://www.red-gate.com/products/sql-development/sql-test/

Page 28: The what, why and how of Unit Testing with SQL Server
Page 29: The what, why and how of Unit Testing with SQL Server

Contact me

[email protected]

@Mrs_Fatherjack