42
© 2019 TEST YOUR PL/SQL WITH utPLSQL JEANNETTE HOLLAND, SENIOR LEAD DEVELOPER DANIEL OVERBY HANSEN, LEAD DEVELOPER

TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

  • Upload
    others

  • View
    22

  • Download
    1

Embed Size (px)

Citation preview

Page 1: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 2019

TEST YOUR PL/SQL WITH utPLSQL

JEANNETTE HOLLAND, SENIOR LEAD DEVELOPER

DANIEL OVERBY HANSEN, LEAD DEVELOPER

Page 2: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 20192

WELCOMELET’S HAVE FUN

Page 3: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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®

Page 4: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 20194

A (VERY) SHORT BIO

THE PRESENTERS

Jeannette HollandSenior Lead Developer

jeannette-holland

Daniel Overby HansenLead Developer

dohdatabase

@dohdatabase

Page 5: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 6: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 20196

WHAT IS utPLSQL?

utPLSQL loves TeamCity and GitHub

Page 7: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 8: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 9: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 20199

THE CODE

SETTING THE SCENE

Page 10: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 11: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 12: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 13: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201913

GETTING STARTED

BUILDING THE utPLSQL TEST

Page 14: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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)

Page 15: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201915

BUILDING THE utPLSQL TEST

BUT the test changed my environment!!!!!

This Photo by Unknown Author is licensed under CC BY-NC-ND

Page 16: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 2019

BUILDING THE utPLSQL TEST

16

SETUP AND TEARDOWN

Page 17: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201917

REFINING

BUILDING THE utPLSQL TEST

Page 18: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201918

REFINING

BUILDING THE utPLSQL TEST

Ah… we caught a bug

This Photo by Unknown Author is licensed under CC BY

Page 19: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201919

BUILDING GREAT TESTS

USING utPLSQL

Page 20: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201920

BUILDING GREAT TESTS

USING utPLSQL

Page 21: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201921

BUILDING GREAT TESTS

USING utPLSQL

Page 22: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201922

CHEAT SHEET

USING utPLSQL

https://www.cheatography.com/jgebal/

Jacek GębalMain contributor

@GebalJacek

Page 23: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201923

CONDITIONAL COMPILATION

USING utPLSQL

Page 24: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 25: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 26: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201926

THE QUICK FIX

FIXING THE PROBLEM

Page 27: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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…

Page 28: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 29: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201929

KEEP THE SUGGESTIONS COMING

FUN WITH PL/SQL

Page 30: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201930

OUR SUGGESTION

FUN WITH PL/SQL

Page 31: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 32: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201932

utPLSQL AS TEAMCITY “AUTO TEST” - DEMO

HOW WE USE IT TODAY

Page 33: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 34: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201934

CI FOR PL/SQL CODE – DEMO

HOW WE USE IT TODAY

Page 35: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201935

CI FOR PL/SQL CODE – CAKE

HOW WE USE IT TODAY

Page 36: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201936

CI FOR PL/SQL CODE – BUILD CONFIGURATION

HOW WE USE IT TODAY

Page 37: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201937

CI FOR PL/SQL CODE – RUN TESTS BEFORE MERGE

HOW WE USE IT TODAY

Page 38: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201938

SO MANY POSSIBILITIES FOR LEARNING MORE ABOUT utPLSQL

HINTS & USEFUL SITES

Page 39: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 201939

SO MANY POSSIBILITIES FOR LEARNING MORE ABOUT utPLSQL

HINTS & USEFUL SITES

Page 40: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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

Page 41: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 2019© 2019

QUESTIONS?

41

Page 42: TEST YOUR PL/SQL WITH utPLSQL · 2019-10-30 · • ORCL database with utPLSQL schema • utPLSQL-cli • TeamCity Build agent TeamCity as “auto test” platform (demo to follow)

© 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.