Database
Testing with
Dan Clark
●
Code can be found at
https://github.com/danclark5/pytesting_db
●
Companion Article is at
https://bruisedthumb.com/post/2018-07-29
Slide 2
Slide 2 text
Who? What? Where?
Slide 3
Slide 3 text
Unit Testing
“Explosion” by Denis De Mesmaeker is licensed under CC BY 2.0
Slide 4
Slide 4 text
Tables, Views, Stored Procedures,
and Functions. Oh My!
“Immersed in Numbers” by Chris Khamken is licensed under CC BY 2.0
Slide 5
Slide 5 text
No content
Slide 6
Slide 6 text
A few caveats
We’re starting with an empty database
Build it up, tear it down!
Database transactions for the win!
Slide 7
Slide 7 text
Fixtures
Slide 8
Slide 8 text
Tests
Slide 9
Slide 9 text
Some helpful pytest
options
●
-s: sets the capture method to "no".
●
-m: runs tests that are marked with a certain string.
●
--pdb: runs the debugger when an error is encountered
●
--lf: runs only the tests that failed on the last attempt.
●
-v: make pytest verbose
Slide 10
Slide 10 text
Setting up our fixtures
Slide 11
Slide 11 text
A word about scope
“Scope” by Tim Lieu is licensed under CC BY 2.0
Slide 12
Slide 12 text
CONFTEST.PY!
Slide 13
Slide 13 text
Setting up our fixtures
Slide 14
Slide 14 text
Let’s make a test
●
Keep it simple Socrates
●
Make sure that tests can connect to the database.
●
Confirms pytests is working.
Slide 15
Slide 15 text
What are we testing
Slide 16
Slide 16 text
What are we testing
Slide 17
Slide 17 text
Let’s make better tests
Slide 18
Slide 18 text
run_sproc???
Slide 19
Slide 19 text
Let’s try it
Slide 20
Slide 20 text
Let’s try it
Slide 21
Slide 21 text
Let’s try it
Slide 22
Slide 22 text
Benefits and Drawbacks
●
Can be migrated to another product
●
Fixtures are reusable
●
Tests and fixtures can be grouped together
●
We can leverage Python’s vast module ecosystem
●
Using assert instead of specialized functions
●
Command line based. However Pycharm to the rescue
●
Code coverage is useless
●
No AssertEqualsTable (tSQLt)
Slide 23
Slide 23 text
●
Code can be found at
https://github.com/danclark5/pytesting_db
●
Companion Article is at
https://bruisedthumb.com/post/2018-07-29
Twitter: @danclark
Thanks!!!!!!!!!!!