SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
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
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
Steven Feuerstein
1999
PLUTO
PL/Unit
ruby-plsql-spec
DBFit
Oracle Database Unit Testing market
Market expectations
The team
● Jacek Gębal
● Pavel Kaplya
● Robert Love
● David Pyke
● Vinicius Avellar
● Samuel Nitsche
● Philipp Salvisberg
Why utPLSQL v3 ? ● free
● open source
● pure PL/SQL
● Tested on 11gR2 - 12cR2
● IDE independent
● database independent
● CI/CD oriented
● modular and extendable
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
The Unit Test
also needs to be
● Simple
● Automated
● Testing one behavior
● Living documentation
● Developer’s responsibility
Delivering software that is:
● Safe to change
● Maintainable
● Can be tested and delivered iteratively
Why should I
care ?
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)
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
Test Driven Development
with utPLSQL v3
● suite structure
● annotations
● expectation syntax
● running tests
● failure and error messages
demo
Summary
Annotation syntax:
--%name( parameter[s] )
Example:
--%suite(description)
--%test(description)
Expectation examples:
ut.expect( 1 ).to_( equal( 1 ) );
ut.expect( ‘Chuck’ ).to_equal( ‘Chuck’ );
Running tests:
exec ut.run();
Annotations
Package:
● --%suite(<description>)
● --%suitepath(<path>)
● --%rollback(auto/manual)
● --%disabled
Test procedure:
● --%test(<description>)
● --%throws(<error_No>[,...])
● --%beforetest(<proc_name>)
● --%aftertest(<proc_name>)
● --%rollback(auto/manual)
● --%disabled
Procedure:
● --%beforeall, --%afterall
● --%beforeeach, --%aftereach
Expectations & matchers
● be_null
● be_true
● be_greater_than( expected )
● be_less_than( expected )
● equal( expected )
● be_like( mask [, escape_char] )
ut.expect( actual ).to_( matcher(param[, param...]) );
ut.expect( actual ).not_to( matcher(param[, param...]) );
● be_not_null
● be_false
● be_greater_or_equal( expected )
● be_less_or_equal( expected )
● be_between( lower, upper )
● match( pattern [, modifiers] )
● be_empty ● have_count( count )
Matchers:
Equality rules in tests
ut.expect( 100 ).to_equal( ‘100’ );
ut.expect( ‘abcdef’ ).to_equal( to_clob( ‘abcdef’ ) );
ut.expect( systimestamp ).to_equal( current_timestamp );
ut.expect( sysdate ).to_equal( ‘20-MAR-2018’ );
When it comes to unit testing ...
Data types matter!
Supported data-types
● clob, blob
● timestamp (with (local) timezone)
● interval (day to second / year to month)
● cursor
● object, nested table, varray type
● number (integer)
● varchar2 (char / varchar)
● date
● boolean
Testing data
● data setup / cleanup
● cursor data comparison
● automatic rollback
● selective comparison
demo
--%suite(Demo suite)
--%beforeall
procedure data_setup_before_all;
--%beforeeach
procedure thing_to_do_before_each_test;
--%test(Does a thing)
procedure test_the_thing;
--%test(Does stuff)
--%beforetest(setup_before_stuff)
--%aftertest(cleanup_after_stuff)
procedure test_stuff;
procedure setup_before_stuff;
procedure cleanup_after_stuff;
--%afterall
procedure cleanup_after_all_is_done;
data_setup_before_all
thing_to_do_before_each_test
test_the_thing
thing_to_do_before_each_test
setup_before_stuff
test_stuff
cleanup_after_stuff
cleanup_after_all_is_done
savepoint before_suite
Order of execution
savepoint before_test
rollback to before_suite
rollback to before_test
savepoint before_test
rollback to before_test
& test isolation
Organizing tests
● suites hierarchy with suitepath
● parent, siblings, ancestors
● shared beforeall / afterall
● suites isolation / setup scope
demo
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
Test run options
● default options
● single schema
● single package
● single test
● suite
● multiple schema
● specifying reporter
demo
utPLSQL - SQL Developer extension
demo
utplsql-cli
● Windows/Linux/Mac
● real-time reporting
● multi-reporting
● Oracle client independent
● CI/CD oriented
demo
Integration
● CI/CD servers
○ Jenkins
○ TeamCity
○ Travis
○ other...
● Sonar
○ generic test results
○ code coverage
● Coveralls
○ code coverage
demo
utPLSQL v3 recap
● free, open-source, pure PL/SQL
● annotations
● human readable syntax
● data type - aware comparison
● automatic test isolation
● rich selection of matchers
● supports cursors, object types, nested tables
● CI/CD oriented
● code coverage
Resources
Cheat-sheet: https://www.cheatography.com/jgebal/cheat-sheets/utplsql-v3/
Documentation: http://utplsql.org/utPLSQL/
Source code: https://github.com/utPLSQL/utPLSQL
Releases: https://github.com/utPLSQL/utPLSQL/releases
utPLSQL-cli: https://github.com/utPLSQL/utPLSQL-cli/releases
SQLDeveloper-extension: https://github.com/utPLSQL/utPLSQL-SQLDeveloper/releases
Twitter: @utplsql
Demo project: https://github.com/utPLSQL/utPLSQL-demo-project
Sonar results: https://sonarcloud.io/dashboard?id=utPLSQL
Coveralls results: https://coveralls.io/github/utPLSQL/utPLSQL
Travis-CI builds: https://travis-ci.org/utPLSQL/utPLSQL

Weitere ähnliche Inhalte

Was ist angesagt?

Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
PostgresOpen
 

Was ist angesagt? (20)

Unit testing framework
Unit testing frameworkUnit testing framework
Unit testing framework
 
Data Driven Framework in Selenium
Data Driven Framework in SeleniumData Driven Framework in Selenium
Data Driven Framework in Selenium
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and Underscores
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
 
JSON and PL/SQL: A Match Made in Database
JSON and PL/SQL: A Match Made in DatabaseJSON and PL/SQL: A Match Made in Database
JSON and PL/SQL: A Match Made in Database
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
 
testng
testngtestng
testng
 
Postgres MVCC - A Developer Centric View of Multi Version Concurrency Control
Postgres MVCC - A Developer Centric View of Multi Version Concurrency ControlPostgres MVCC - A Developer Centric View of Multi Version Concurrency Control
Postgres MVCC - A Developer Centric View of Multi Version Concurrency Control
 
Turbocharge SQL Performance in PL/SQL with Bulk Processing
Turbocharge SQL Performance in PL/SQL with Bulk ProcessingTurbocharge SQL Performance in PL/SQL with Bulk Processing
Turbocharge SQL Performance in PL/SQL with Bulk Processing
 
TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PB
 
MySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsMySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 Tips
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools short
 
SQLcl overview - A new Command Line Interface for Oracle Database
SQLcl overview - A new Command Line Interface for Oracle DatabaseSQLcl overview - A new Command Line Interface for Oracle Database
SQLcl overview - A new Command Line Interface for Oracle Database
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
 
KSUG 스프링캠프 2019 발표자료 - "무엇을 테스트할 것인가, 어떻게 테스트할 것인가"
KSUG 스프링캠프 2019 발표자료 - "무엇을 테스트할 것인가, 어떻게 테스트할 것인가"KSUG 스프링캠프 2019 발표자료 - "무엇을 테스트할 것인가, 어떻게 테스트할 것인가"
KSUG 스프링캠프 2019 발표자료 - "무엇을 테스트할 것인가, 어떻게 테스트할 것인가"
 
How to find what is making your Oracle database slow
How to find what is making your Oracle database slowHow to find what is making your Oracle database slow
How to find what is making your Oracle database slow
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
What is new in PostgreSQL 14?
What is new in PostgreSQL 14?What is new in PostgreSQL 14?
What is new in PostgreSQL 14?
 

Ähnlich wie prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle

Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source Frameworks
Dimitry Polivaev
 
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
Beyond unit tests: Deployment and testing for Hadoop/Spark workflowsBeyond unit tests: Deployment and testing for Hadoop/Spark workflows
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
DataWorks Summit
 

Ähnlich wie prohuddle-utPLSQL v3 - Ultimate unit testing framework for Oracle (20)

Bgoug 2019.11 test your pl sql - not your patience
Bgoug 2019.11   test your pl sql - not your patienceBgoug 2019.11   test your pl sql - not your patience
Bgoug 2019.11 test your pl sql - not your patience
 
QA Meetup at Signavio (Berlin, 06.06.19)
QA Meetup at Signavio (Berlin, 06.06.19)QA Meetup at Signavio (Berlin, 06.06.19)
QA Meetup at Signavio (Berlin, 06.06.19)
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
 
Free oracle performance tools
Free oracle performance toolsFree oracle performance tools
Free oracle performance tools
 
Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)
 
Q4.11: Getting Started in LAVA
Q4.11: Getting Started in LAVAQ4.11: Getting Started in LAVA
Q4.11: Getting Started in LAVA
 
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
 
Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source Frameworks
 
Testing Django APIs
Testing Django APIsTesting Django APIs
Testing Django APIs
 
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
Beyond unit tests: Deployment and testing for Hadoop/Spark workflowsBeyond unit tests: Deployment and testing for Hadoop/Spark workflows
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
 
NovaProva, a new generation unit test framework for C programs
NovaProva, a new generation unit test framework for C programsNovaProva, a new generation unit test framework for C programs
NovaProva, a new generation unit test framework for C programs
 
Curating Your Cukes by Eric Kessler
Curating Your Cukes by Eric KesslerCurating Your Cukes by Eric Kessler
Curating Your Cukes by Eric Kessler
 
Unit testing
Unit testingUnit testing
Unit testing
 
Pl sql office hours data setup and teardown in database testing
Pl sql office hours   data setup and teardown in database testingPl sql office hours   data setup and teardown in database testing
Pl sql office hours data setup and teardown in database testing
 
Introduction to unit testing in python
Introduction to unit testing in pythonIntroduction to unit testing in python
Introduction to unit testing in python
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Developers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomonDevelopers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomon
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NET
 
A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)
 
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQLPOUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
 

Kürzlich hochgeladen

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
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
  • 13. demo
  • 14. Summary Annotation syntax: --%name( parameter[s] ) Example: --%suite(description) --%test(description) Expectation examples: ut.expect( 1 ).to_( equal( 1 ) ); ut.expect( ‘Chuck’ ).to_equal( ‘Chuck’ ); Running tests: exec ut.run();
  • 15. Annotations Package: ● --%suite(<description>) ● --%suitepath(<path>) ● --%rollback(auto/manual) ● --%disabled Test procedure: ● --%test(<description>) ● --%throws(<error_No>[,...]) ● --%beforetest(<proc_name>) ● --%aftertest(<proc_name>) ● --%rollback(auto/manual) ● --%disabled Procedure: ● --%beforeall, --%afterall ● --%beforeeach, --%aftereach
  • 16. Expectations & matchers ● be_null ● be_true ● be_greater_than( expected ) ● be_less_than( expected ) ● equal( expected ) ● be_like( mask [, escape_char] ) ut.expect( actual ).to_( matcher(param[, param...]) ); ut.expect( actual ).not_to( matcher(param[, param...]) ); ● be_not_null ● be_false ● be_greater_or_equal( expected ) ● be_less_or_equal( expected ) ● be_between( lower, upper ) ● match( pattern [, modifiers] ) ● be_empty ● have_count( count ) Matchers:
  • 17. Equality rules in tests ut.expect( 100 ).to_equal( ‘100’ ); ut.expect( ‘abcdef’ ).to_equal( to_clob( ‘abcdef’ ) ); ut.expect( systimestamp ).to_equal( current_timestamp ); ut.expect( sysdate ).to_equal( ‘20-MAR-2018’ ); When it comes to unit testing ... Data types matter!
  • 18. Supported data-types ● clob, blob ● timestamp (with (local) timezone) ● interval (day to second / year to month) ● cursor ● object, nested table, varray type ● number (integer) ● varchar2 (char / varchar) ● date ● boolean
  • 19. Testing data ● data setup / cleanup ● cursor data comparison ● automatic rollback ● selective comparison
  • 20. demo
  • 21. --%suite(Demo suite) --%beforeall procedure data_setup_before_all; --%beforeeach procedure thing_to_do_before_each_test; --%test(Does a thing) procedure test_the_thing; --%test(Does stuff) --%beforetest(setup_before_stuff) --%aftertest(cleanup_after_stuff) procedure test_stuff; procedure setup_before_stuff; procedure cleanup_after_stuff; --%afterall procedure cleanup_after_all_is_done; data_setup_before_all thing_to_do_before_each_test test_the_thing thing_to_do_before_each_test setup_before_stuff test_stuff cleanup_after_stuff cleanup_after_all_is_done savepoint before_suite Order of execution savepoint before_test rollback to before_suite rollback to before_test savepoint before_test rollback to before_test & test isolation
  • 22. Organizing tests ● suites hierarchy with suitepath ● parent, siblings, ancestors ● shared beforeall / afterall ● suites isolation / setup scope
  • 23. demo
  • 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
  • 26. demo
  • 27. utPLSQL - SQL Developer extension
  • 28. demo
  • 29. utplsql-cli ● Windows/Linux/Mac ● real-time reporting ● multi-reporting ● Oracle client independent ● CI/CD oriented
  • 30. demo
  • 31. Integration ● CI/CD servers ○ Jenkins ○ TeamCity ○ Travis ○ other... ● Sonar ○ generic test results ○ code coverage ● Coveralls ○ code coverage
  • 32. demo
  • 33. utPLSQL v3 recap ● free, open-source, pure PL/SQL ● annotations ● human readable syntax ● data type - aware comparison ● automatic test isolation ● rich selection of matchers ● supports cursors, object types, nested tables ● CI/CD oriented ● code coverage
  • 34. Resources Cheat-sheet: https://www.cheatography.com/jgebal/cheat-sheets/utplsql-v3/ Documentation: http://utplsql.org/utPLSQL/ Source code: https://github.com/utPLSQL/utPLSQL Releases: https://github.com/utPLSQL/utPLSQL/releases utPLSQL-cli: https://github.com/utPLSQL/utPLSQL-cli/releases SQLDeveloper-extension: https://github.com/utPLSQL/utPLSQL-SQLDeveloper/releases Twitter: @utplsql Demo project: https://github.com/utPLSQL/utPLSQL-demo-project Sonar results: https://sonarcloud.io/dashboard?id=utPLSQL Coveralls results: https://coveralls.io/github/utPLSQL/utPLSQL Travis-CI builds: https://travis-ci.org/utPLSQL/utPLSQL