Fundamentals of Unit Testing and TDD as a practice and presentation of core features available with utPLSQL v3.
Unit testing for Oracle Databases and PLSQL programming language.
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle
1. utPLSQL v3
Ultimate Unit Testing framework for Oracle
Jacek Gębal
twitter: @GebalJacek
mail: jgebal@gmail.com
blog: oraclethoughts.com
Principal Data Engineer Developer
@Fidelity Investments - Ireland
co-author of: utPLSQL v3
2. Plan
● Oracle Database testing tools
● utPLSQL v3
● Rules of unit testing
● Test Driven Development with utPLSQL
● Testing data
● Test run options
● Suites
● utPLSQL - SQL Developer extension
● utPLSQL-cli - running tests from command line
● CI/CD integration
5. The team
● Jacek Gębal
● Pavel Kaplya
● Robert Love
● David Pyke
● Vinicius Avellar
● Samuel Nitsche
● Philipp Salvisberg
6. Why utPLSQL v3 ? ● free
● open source
● pure PL/SQL
● Tested on 11gR2 - 12cR2
● IDE independent
● database independent
● CI/CD oriented
● modular and extendable
7. Properties of
Unit Tests
● Fast
● Isolated
● Repeatable
● Self-verifying
● Thorough & Timely
https://github.com/.../F.I.R.S.T-Principles-of-Unit-Testing
https://pragprog.com/.../2012-01/unit-tests-are-first
8. The Unit Test
also needs to be
● Simple
● Automated
● Testing one behavior
● Living documentation
● Developer’s responsibility
9. Delivering software that is:
● Safe to change
● Maintainable
● Can be tested and delivered iteratively
Why should I
care ?
10. What to test in
database ?
● Behavior
○ Logic
○ in / out structure
○ State (?)
● Avoid
○ under-testing
○ over-testing
○ meaningless tests
○ flaky tests
○ aiming for metrics (coverage/test count)
11. Test Driven Development
● write a test
● make it fail
● keep it simple
● tests are examples
● tests become
documentation
● get to green fast
● take baby steps
● stuck?
undo and start over
● write only enough
code to pass the test
● remove duplication
(in code and tests)
● rename and clean up
● run tests and stay green
● change implementation,
not behavior
● improve structure
in small steps
RED GREEN
REFACTOR
With TDD you get:
● Fast feedback loop
● Visible progress
● Code is tested before it exists
● Accomplishment
with every new test
12. Test Driven Development
with utPLSQL v3
● suite structure
● annotations
● expectation syntax
● running tests
● failure and error messages
24. package test_add_room_content as
--%suite(Add content to a room)
--%suitepath(org.utplsql.demo.test_rooms)
package test_remove_rooms_by_name as
--%suite(Remove rooms by name)
--%suitepath(org.utplsql.demo.test_rooms)
package test_rooms as
--%suite
--%suitepath(org.utplsql.demo)
package test_betwnstr as
--%suite(description)
savepoint
rollback to savepoint
Suite hierarchy test run
utplsql
test_betwnstr
test_rooms
test_add_room_content test_remove_rooms_by_name
org
demo
savepoint
rollback to savepoint
savepoint
rollback to savepoint
25. Test run options
● default options
● single schema
● single package
● single test
● suite
● multiple schema
● specifying reporter