TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema •...
Transcript of TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema •...
© 2019
TEST YOUR PL/SQL WITH utPLSQL
JEANNETTE HOLLAND, SENIOR LEAD DEVELOPER
DANIEL OVERBY HANSEN, LEAD DEVELOPER
© 20192
WELCOMELET’S HAVE FUN
© 20193
BRINGING INTEGRATED SOLUTIONS TO INVESTMENT MANAGERS
THE WORLD’S LEADING PROVIDER
• Global provider of software and services to financial industry
• Established in 1971
• Headquartered in Copenhagen, Denmark
• Offices across Europe, North America and Asia-Pacific
• Flagship product, SimCorp Dimension®, built on-top of Oracle Database
• More than USD 20 trillion managed on SimCorp Dimension®
© 20194
A (VERY) SHORT BIO
THE PRESENTERS
Jeannette HollandSenior Lead Developer
jeannette-holland
Daniel Overby HansenLead Developer
dohdatabase
@dohdatabase
© 20195
WHAT’S IN IT FOR YOU
GOAL
1 Inspire you to do more tests
2 Demonstrate ease of use of utPLSQL
3 Show benefits of a Continuous Integration pipeline
4 Have fun talking about PL/SQL
© 20196
WHAT IS utPLSQL?
utPLSQL loves TeamCity and GitHub
© 20197
HOW TO GET STARTED
utPLSQL
1
2
3
Download from GitHub
https://github.com/utPLSQL/utPLSQL/releases
Install the utPLSQL database schema (UT3)
@utPLSQL\source\install_headless.sql
Configure schema holding the unit tests
@utPLSQL\source\create_user_grants.sql
@utPLSQL\source\create_user_synonyms.sql
Plus other grants required
4 Create and run unit tests (more in just a moment)
This Photo by Unknown Author is licensed under CC BY
© 20198
THE TASK AT HAND
SETTING THE SCENE
User Story:
As an application user
I want a “single-source-of-truth” when retrieving current time in UTC
So that I can compare time regardless of my location
Acceptance criteria:
• Get UTC time from the database in fractional format
• Must work in globalized environment
• All services, regardless of underlying programming language, must get UTC timestamp from the
database.
• Must support “fixed time” testing
© 20199
THE CODE
SETTING THE SCENE
© 201910
WHAT HAPPENED
SETTING THE SCENE
1 When released customer defects occasionally started flowing in
2 Developer tried to reproduce, works on my machine, defect rejected
3 More defects came in…
4Developer set up a distributed scenario by using
next-seat colleague’s computer, works on OUR machines, defect rejected
© 201911
WHAT HAPPENED
SETTING THE SCENE
5 Developer claimed something is wrong with the customer
6One customer said: “Well, it usually happens on Citrix after I get an error about a
missing Windows profile, and something about resetting language settings…”
7Language settings you say – let’s make a unit test that fools around with
NLS stuff and time zones
© 2019
BUILDING THE utPLSQL TEST
12
GETTING STARTED
• --%suite must always come right after AS
• Default rollback method is auto
• Setup and teardown functions
• Can also have --%beforeeach / --%aftereach
© 201913
GETTING STARTED
BUILDING THE utPLSQL TEST
© 2019
BUILDING THE utPLSQL TEST
14
GETTING STARTED
• Remember to set serverout on
• Here default output is shown
• other output formats available (e.g. for Team City)
© 201915
BUILDING THE utPLSQL TEST
BUT the test changed my environment!!!!!
This Photo by Unknown Author is licensed under CC BY-NC-ND
© 2019
BUILDING THE utPLSQL TEST
16
SETUP AND TEARDOWN
© 201917
REFINING
BUILDING THE utPLSQL TEST
© 201918
REFINING
BUILDING THE utPLSQL TEST
Ah… we caught a bug
This Photo by Unknown Author is licensed under CC BY
© 201919
BUILDING GREAT TESTS
USING utPLSQL
© 201920
BUILDING GREAT TESTS
USING utPLSQL
© 201921
BUILDING GREAT TESTS
USING utPLSQL
© 201922
CHEAT SHEET
USING utPLSQL
https://www.cheatography.com/jgebal/
Jacek GębalMain contributor
@GebalJacek
© 201923
CONDITIONAL COMPILATION
USING utPLSQL
© 201924
THE CODE
FIXING THE PROBLEM
1 To get UTC time we use function SYS_EXTRACT_UTC
2Logically, to convert something in UTC
you need to know the time zone to convert from
3OK, but we are using SYSTIMESTAMP?
It does hold the time zone information
© 201925
THE CODE
FIXING THE PROBLEM
1True, but we are using our own “cover” function
in order to support “fixed time” test mode
2 Our function returns a TIMESTAMP
3SYSTIMESTAMP returns a
TIMESTAMP WITH TIME ZONE
4Implicit conversion throws away
the time zone information
1True, but we are using our own “cover” function
in order to support “fixed time” test mode
2 Our function returns a TIMESTAMP
3SYSTIMESTAMP returns a
TIMESTAMP WITH TIME ZONE
© 201926
THE QUICK FIX
FIXING THE PROBLEM
© 201927
LESSONS LEARNED
FIXING THE PROBLEM
1 RTFM – Read The F****** Manual
2Implicit conversions are the mother
of all F*** Ups
3 Build better tests…
© 201928
IMPROVE THE CODE
FUN WITH PL/SQL
1 Let’s improve the sample code together
2 Don’t be shy – all suggestions are welcome
3First three suggestions get a prize
Danish speciality – salty liquorice
© 201929
KEEP THE SUGGESTIONS COMING
FUN WITH PL/SQL
© 201930
OUR SUGGESTION
FUN WITH PL/SQL
© 201931
OUR SETUP
HOW WE USE IT TODAY
1
2
3
Build server
• ORCL database with utPLSQL schema
• utPLSQL-cli
• TeamCity Build agent
TeamCity as “auto test” platform (demo to follow)
CI for PL/SQL code (demo to follow)
• Runs utPLSQL tests on Pull Request for our PL/SQL scripts
• If the tests fail no merge of the script
• Cake script puts it together
© 201932
utPLSQL AS TEAMCITY “AUTO TEST” - DEMO
HOW WE USE IT TODAY
© 2019
Build server
ORCL
PLSQL script repository
33
CI FOR PL/SQL CODE
HOW WE USE IT TODAY
SQL Developer GIT interface
Merge changes
1. Copy script to build server
2. Run script in ORCL database
3. Run utPLSQL unit tests in
ORCL database
4. Merge branch if test ok
© 201934
CI FOR PL/SQL CODE – DEMO
HOW WE USE IT TODAY
© 201935
CI FOR PL/SQL CODE – CAKE
HOW WE USE IT TODAY
© 201936
CI FOR PL/SQL CODE – BUILD CONFIGURATION
HOW WE USE IT TODAY
© 201937
CI FOR PL/SQL CODE – RUN TESTS BEFORE MERGE
HOW WE USE IT TODAY
© 201938
SO MANY POSSIBILITIES FOR LEARNING MORE ABOUT utPLSQL
HINTS & USEFUL SITES
© 201939
SO MANY POSSIBILITIES FOR LEARNING MORE ABOUT utPLSQL
HINTS & USEFUL SITES
© 201940
KEY TAKE-AWAYS
SUMMARY
1 Unit testing is easy and adds value
2 Go home – and get started
3 Always RTFM - Read The F****** Manual
4Remember to praise those dedicated people
that use precious time on creating open source
© 2019© 2019
QUESTIONS?
41
© 2019
LEGAL NOTICE
The contents of this publication are for general information and illustrative purposes only and are used at the reader’s own risk. SimCorp uses all reasonable endeavors to ensure the accuracy of the information. However, SimCorp does not guarantee or warrant
the accuracy, completeness, factual correctness, or reliability of any information in this publication and does not accept liability for errors, omissions, inaccuracies, or typographical errors. The views and opinions expressed in this publication are not necessarily
those of SimCorp. © 2019 SimCorp A/S. All rights reserved. Without limiting rights under copyright, no part of this document may be reproduced, stored in, or introduced into a retrieval system, or transmitted in any form, by any means (electronic, mechanical,
photocopying, recording, or otherwise), or for any purpose without the express written permission of SimCorp A/S. SimCorp, the SimCorp logo, SimCorp ®, and SimCorp Services are either registered trademarks or trademarks of SimCorp A/S in Denmark and/or
other countries. Refer to www.simcorp.com/trademarks for a full list of SimCorp A/S trademarks. Other trademarks referred to in this document are the property of their respective owners.