SlideShare une entreprise Scribd logo
1  sur  32
utPLSQL
A Unit Testing Framework for
Oracle PL/SQL Code
Achieving PL/SQL Excellence
Steven Feuerstein
Original creator of utPLSQL, not currently active on project (2016)
Visit the Github Repo for utPLSQL: http://https://github.com/utPLSQL
Aw, Gee, Mom, do I have to test
my code? Only if you want:
 Successful applications
– That is the whole point, after all.
 Successful applications on time
– "We don't have time to test"? Hah! Solid testing improves the
chances of putting out quality code on time.
 Developer and user confidence
– It's a wonderful feeling to know that our code really and truly
works.
– Our users then love us and support us.
Different Kinds of Tests
 Functional, System, Integration tests
– Written by the software customer, it answers the question
“What do I need to verify before I am confident this feature
works?”
 Many other types of tests
– Stress tests – real-world workload testing
– Monkey tests – tests responses to unusual conditions
– Parallel tests – compares behavior of new and old systems
 And then there are unit tests...
– Written by the developer, they test
individual units (procedure or function
in PL/SQL)
The focus in
this
presentation.
Wouldn't it be great if...
 It was easy to construct tests
– An agreed-upon and effective approach to test construction that
everyone can understand and follow
 It was easy to run tests
– And see the results, instantly and automatically.
 Testing were completely integrated into my
development, QA and maintenance processes
– No program goes to QA until it has passed a battery of tests
– Anyone can maintain with confidence, because my test suite
automatically validates my changes
POLL
 How do you (or your team) unit test your PL/SQL
code today?
 Possible answers:
– Everyone does their own thing and we hope for the
best.
– Our users test our code.
– We have a formal test process
– We use automated testing software
Typical Development
and Testing Scenario
 Let's walk through a typical development/test
flow, critique it, and then take a look at how you
might do the same thing with utPLSQL
 We'll use a very simple example:
– building an improvement to the SUBSTR function
Improving upon SUBSTR
 SUBSTR returns the sub-string specified by start
position and number of characters.
just10 := SUBSTR (full_string, 3, 10);
Grab 10 characters staring
from 3rd position
 Suppose I have the starting and
ending positions (or even sub-
strings). How do I use SUBSTR
to solve this problem?
mystring := SUBSTR (full_string, 5, 17); -- start and end? Nah...
mystring := SUBSTR (full_string, 5, 12); -- end – start?
mystring := SUBSTR (full_string, 5, 13); -- end – start + 1?
mystring := SUBSTR (full_string, 5, 11); -- end – start - 1?
Grab everything between the
5th and 17th position
But which of these
does the job?
A Straightforward Abstraction
 Create a “between string” function that works with
starting and ending positions
CREATE OR REPLACE FUNCTION betwnStr (
string_in IN VARCHAR2,
start_in IN INTEGER,
end_in IN INTEGER
)
RETURN VARCHAR2
IS
BEGIN
RETURN (
SUBSTR (
string_in,
start_in,
end_in – start_in + 1
)
);
END;
myString := betwnStr (yourString, 5, 17);
A Truly Crude
Testing Technique
 Let’s see…what should I check for?
SQL> exec DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 3, 5));
cde
And so on, and so forth...very time consuming, very haphazard...and
what happens when you want to run the tests a second time?
 Oh, and what about this?
SQL> exec DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 0, 2));
ab
 Here's a good one:
SQL> exec DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 3, 100));
cdefgh
Slightly Better:
Build a Test Script
 Let’s see…what should I check for?
BEGIN
DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 3, 5));
DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 0, 2));
DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', NULL, 5));
DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 3, NULL));
DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 3, 100));
DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', -3, -5));
DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', -3, 0));
END;
/
SQL> @betwnstr.tst
cde
ab
cdefgh
fgh
Yielding this
output:
Which tells us
what precisely?
Problems with Typical Testing
 Almost entirely ad hoc
– No comprehensive effort to compile test cases
– No infrastructure to record cases and administer tests
 Difficult to verify correctness
– If you wrote the program you might know that it was supposed
to be “abc” or “abcd”
– But what about somebody who comes along to maintain the
code?
 Reliance on the user community to test
– Since we are never really sure we’ve tested properly, we rely
on our users (or, we are lucky, the QA department) to finish our
job
There has got to be a better way!
How About Extreme Programming?
 "Extreme programming" sounds, well, extreme
– It really isn't
– It takes well-accepted ideas about programming and
takes them to extremes
 Resources on extreme programming:
– www.xprogramming.com
– www.extremeprogramming.org
– Extreme Programming Explained by Kent Beck
– Extreme Programming Installed by Ron Jeffries, et al
– Planning Extreme Programming by Ron Jeffries, et al
Common Sense Taken to
Extremes
 If code reviews are good, we'll review code all the time
(pair programming)
 If testing is good, everybody will test all the time (unit
testing), even the customers (functional testing)
 If design is good, we'll make it a part of everybody's daily
business (refactoring)
 If simplicity is good, we'll always leave the system with
the simplest design that supports its current functionality
(the simplest thing that could possibly work)
A selection of extremes from XP Explained, Beck
Extreme Unit
Testing Principles
 Write unit tests first!
 Code a little, test a lot
 Build automated red light-green light tests
If testing is good, everybody will test all the time
Write Unit Tests First
 What is my program supposed to do?
– By writing the test first, you concentrate more on the interface
than the implementation
 Write unit tests…
– Before you start writing your program
– Before you fix a bug (turn each bug report into a test case)
– To "document" each enhancement request -- then implement
All of string from
starting point.
Positive # greater than
length of string
Positive #
NULLSmaller positive #Positive #
NULLNULLNOT NULL
NULLNULLNULL
ResultEnd ValueStart Value
Code a Little, Test a Lot
 We are all in a hurry to get our coding done, but the
reality is that most of our time is spent on debugging,
not writing code
– We need to develop our code cleaner the "first time"
 Incremental development, coupled with comprehensive
testing, will improve productivity and code quality
simultaneously
– Make small changes, then test
– Add small pieces of functionality, then test
– Constantly add to your test cases for the unit test
Automated, Red Light-Green
Light Tests
 If we are going to build lots of tests and run them often,
we need to be able to run those tests easily
– This includes the setting up and cleaning up of test data and
other elements
– If this process is not automated, developers will not test
 A developer should be able to determine at a glance
whether the code passed its unit tests
– Do not leave it up to the developer to analyze the results to
determine the status of the tests
 This is called the red-light, green-light approach
– Your code does not work until you get a "green light" – 100%
success
Testing the utPLSQL Way
 A unit testing “framework” for PL/SQL
developers
– Set of processes and code that conform to the
Extreme Programming unit testing principles
SQL> exec utplsql.test ('betwnstr')
.
> SSSS U U CCC CCC EEEEEEE SSSS SSSS
> S S U U C C C C E S S S S
> S U U C C C C E S S
> S U U C C E S S
> SSSS U U C C EEEE SSSS SSSS
> S U U C C E S S
> S U U C C C C E S S
> S S U U C C C C E S S S S
> SSSS UUU CCC CCC EEEEEEE SSSS SSSS
.
SUCCESS: "betwnstr"
utPLSQL Architecture
 utPLSQL is a fun demonstration of the use of dynamic SQL (really,
dynamic PL/SQL) and packaged data
– utPLSQL.test constructs the names of and executes the setup, unit test
and teardown procedures based on the program name you provide.
– utAssert populates a collection with results (failure) data
ut_Setup
ut_TestMe
ut_Teardown
utPLSQL.test
Test Engine
Your Test Package
Results Array
Test for Nulls
Invalid ID
Valid ID
Start date too late
End date too early
Name unique
Report Results
1
2
3
4
Assert EQ
Assert NULL
Assert EqTable
Assertion API
5
Steps in Using utPLSQL
Step 1. Download and install utPLSQL
Step 2. Choose a program to test and identify the test cases
Step 3. Build a test package that incorporates those test cases
Step 4. Run your test using the utPLSQL engine
Download and Install utPLSQL
 Visit http://oracle.oreilly.com/utplsql
 Unzip, open up the documentation, install the
utPLSQL software base, and you are ready to
test
– Installs in Oracle7, Oracle8 and Oracle8i
– You can create a separate schema to hold utPLSQL
source or install a version for each developer
Choose Program,
Define Test Cases
 You can test stand-alone procedures or packages, test
the entire set of programs in a package or test a subset
of those programs
– Start with a small program to try out the approach.
 Build your grid of input values and expected outputs.
 Once test cases are defined, it is time to translate them
into code...the test package!
Build a Test Package
 Build a test package that
contains a unit test for each
program in your package
 Must conform to the
standard utPLSQL API:
– Public setup and teardown
procedures
– Separate procedures for each
unit test
 Best approach: generate the
starting point of the test
package with the utGen
package
SQL> exec utGen.testpkg ('betwnstr');
CREATE OR REPLACE PACKAGE ut_betwnstr
IS
PROCEDURE ut_setup;
PROCEDURE ut_teardown;
PROCEDURE ut_BETWNSTR;
END ut_betwnstr;
/
CREATE OR REPLACE PACKAGE BODY ut_betwnstr
IS
PROCEDURE ut_setup ... END;
PROCEDURE ut_teardown ... END;
PROCEDURE ut_BETWNSTR IS
BEGIN
utAssert.this (
'Test of BETWNSTR',
BETWNSTR(
STRING_IN => '',
START_IN => '',
END_IN => '')
);
END ut_BETWNSTR;
END ut_betwnstr;
Generate a Test Package
 You can even pass an argument grid directly to
utGen to generate virtually complete unit test
packages.
DECLARE
utc VARCHAR2 (1000)
:=
'betwnstr|normal|abcdefgh;3;5|cde|eq
betwnstr|zero start|abcdefgh;0;2|!SUBSTR(''abcdefgh'',0,2)|eq
betwnstr|null start|abcdefgh;!null;2|null|isnull
betwnstr|null end|abcdefgh;!3;!null|null|isnull';
BEGIN
utgen.testpkg_from_string ('betwnstr',
utc,
output_type_in=> utgen.c_file,
dir_in=> ''d:openoracleutplsqlexamples''
);
END;
One line for
each set of IN
parameters
and expected
result.
Example of Gen'd Test Code
 It can take lots of code
to properly test a
program.
 The more you can
generate, the better.
PROCEDURE ut_BETWNSTR
IS
against_this VARCHAR2(2000);
check_this VARCHAR2(2000);
BEGIN
-- Define "control" operation for "normal"
against_this := SUBSTR ('abcdefg',0,2);
-- Execute test code for "normal"
check_this :=
BETWNSTR (
STRING_IN => 'abcdefgh'
,
START_IN => 0
,
END_IN => 2
);
-- Assert success for "normal"
utAssert.eq (
'normal',
check_this,
against_this
);
...
100% Generation!
Complete Unit Test Proc
 Every unit test
procedure consists of
three main parts (which
are sometimes
collapsed together,
depending on the
simplicity of the code
being tested):
– Set up the control
(which might already be
done with the set up
procedure).
– Run the code to be
tested.
– Compare results using
the utAssert package
PROCEDURE ut_del1
IS
fdbk PLS_INTEGER;
BEGIN
/* Delete that finds no rows. */
EXECUTE IMMEDIATE '
DELETE FROM ut_DEL1
WHERE employee_id = -1';
te_employee.del (
-1, rowcount_out => fdbk);
utassert.eqtable (
'No rows deleted', 'EMPLOYEE',
'ut_DEL1');
EXCEPTION
WHEN OTHERS
THEN
utassert.this (
'DEL1 exception ' || SQLERRM,
SQLCODE = 0
);
END;
Control
Test
Compare
Error Failure
Apply utAssertion Validators
 The utAssert offers a set of pre-defined assertion programs
that test for the condition you specify and record any failures
for later red light-green light reports. You can assert that:
– Two scalars, tables, collections, pipes, files and queries are equal
– A value is NULL or is NOT NULL
– A Boolean expression is TRUE
PROCEDURE ut_BETWNSTR IS
BEGIN
...
utAssert.eq ('Typical valid usage',
BETWNSTR(STRING_IN => 'abcdefg',
START_IN => 3, END_IN => 5),
'cde');
utAssert.eqFile ('Dump book data',
file1, loc1,
file2, loc2);
Set up & Tear Down Test Data
 The ut_setup and ut_teardown procedures manage
any data structures needed to run your tests
– These programs are run automatically before and after
tests procedures are executed.
PROCEDURE ut_teardown IS
BEGIN
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE ut_employee';
EXCEPTION
WHEN OTHERS THEN NULL;
END;
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE ut_DEL1';
EXCEPTION
WHEN OTHERS THEN NULL;
END;
...
This is an
example of a
portion of the
tear-down used
to test a table
encapsulation
package
Run Your Test
 Once you have built your test package, you can
simply "hand it over" to utPLSQL for testing with a
simple one-line call:
 You can also construct test "suites" of multiple
packages to test and then run that suite:
SQL> exec utPLSQL.test ('betwnstr');
SQL> exec utPLSQL.testSuite ('PLVision');
See Your Results Instantly
 You are notified of success or failure
– When there is a failure, you see the descriptions of
failed test cases, plus information about the cause of the failure
SQL> exec utplsql.test ('betwnstr')
.
> FFFFFFF AA III L U U RRRRR EEEEEEE
> F A A I L U U R R E
> F A A I L U U R R E
> F A A I L U U R R E
> FFFF A A I L U U RRRRRR EEEE
> F AAAAAAAA I L U U R R E
> F A A I L U U R R E
> F A A I L U U R R E
> F A A III LLLLLLL UUU R R EEEEEEE
.
FAILURE: "betwnstr"
.
UT_BETWNSTR: Typical valid usage; expected "cde", got "cd"
UT_BETWNSTR: IS NULL: NULL start
UT_BETWNSTR: IS NULL: End smaller than start
Change Your Testing Ways
 utPLSQL can make a dramatic difference in your ability
to test and your confidence in the resulting code
 With utPLSQL, you build a comprehensive "library" of
unit tests as you build your application
– These tests and all their test cases can be passed on to other
developers
– Anyone can now enhance or maintain the code with
confidence. Make your changes and run the tests. If you get
a green light, you're OK!
Challenges to Using utPLSQL
 Build the test packages
– This can be almost as complicated as writing your application
code.
 Set up/change the test process in your group
– It can be very difficult to move from ad-hoc testing to formal
testing.
 Powerful, well-designed GUI interfaces can make a big
difference.
– Quest is currently exploring how to support utPLSQL in its
development tools.

Contenu connexe

Tendances

TFA Collector - what can one do with it
TFA Collector - what can one do with it TFA Collector - what can one do with it
TFA Collector - what can one do with it Sandesh Rao
 
Apache Flink in the Cloud-Native Era
Apache Flink in the Cloud-Native EraApache Flink in the Cloud-Native Era
Apache Flink in the Cloud-Native EraFlink Forward
 
Free Load Testing Tools for Oracle Database – Which One Do I Use?
Free Load Testing Tools for Oracle Database – Which One Do I Use?Free Load Testing Tools for Oracle Database – Which One Do I Use?
Free Load Testing Tools for Oracle Database – Which One Do I Use?Christian Antognini
 
PostgreSQL and Benchmarks
PostgreSQL and BenchmarksPostgreSQL and Benchmarks
PostgreSQL and BenchmarksJignesh Shah
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Mydbops
 
Introduction to Robot Framework – Exove
Introduction to Robot Framework – ExoveIntroduction to Robot Framework – Exove
Introduction to Robot Framework – ExoveExove
 
Spring batch introduction
Spring batch introductionSpring batch introduction
Spring batch introductionAlex Fernandez
 
OOW15 - Testing Oracle E-Business Suite Best Practices
OOW15 - Testing Oracle E-Business Suite Best PracticesOOW15 - Testing Oracle E-Business Suite Best Practices
OOW15 - Testing Oracle E-Business Suite Best Practicesvasuballa
 
DBA_FEATURE_USAGE_STATISTICS
DBA_FEATURE_USAGE_STATISTICSDBA_FEATURE_USAGE_STATISTICS
DBA_FEATURE_USAGE_STATISTICSMartin Berger
 
SQL Server Performance Tuning Baseline
SQL Server Performance Tuning BaselineSQL Server Performance Tuning Baseline
SQL Server Performance Tuning Baseline► Supreme Mandal ◄
 
Oracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleOracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleEDB
 
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
[EPPG] Oracle to PostgreSQL, Challenges to OpportunityEqunix Business Solutions
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework OpenDaylight
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
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 slowSolarWinds
 
What's new in Oracle 19c & 18c Recovery Manager (RMAN)
What's new in Oracle 19c & 18c Recovery Manager (RMAN)What's new in Oracle 19c & 18c Recovery Manager (RMAN)
What's new in Oracle 19c & 18c Recovery Manager (RMAN)Satishbabu Gunukula
 
How We Optimize Spark SQL Jobs With parallel and sync IO
How We Optimize Spark SQL Jobs With parallel and sync IOHow We Optimize Spark SQL Jobs With parallel and sync IO
How We Optimize Spark SQL Jobs With parallel and sync IODatabricks
 
Oracle Database on Docker - Best Practices
Oracle Database on Docker - Best PracticesOracle Database on Docker - Best Practices
Oracle Database on Docker - Best Practicesgvenzl
 

Tendances (20)

TFA Collector - what can one do with it
TFA Collector - what can one do with it TFA Collector - what can one do with it
TFA Collector - what can one do with it
 
Apache Flink in the Cloud-Native Era
Apache Flink in the Cloud-Native EraApache Flink in the Cloud-Native Era
Apache Flink in the Cloud-Native Era
 
Free Load Testing Tools for Oracle Database – Which One Do I Use?
Free Load Testing Tools for Oracle Database – Which One Do I Use?Free Load Testing Tools for Oracle Database – Which One Do I Use?
Free Load Testing Tools for Oracle Database – Which One Do I Use?
 
PostgreSQL and Benchmarks
PostgreSQL and BenchmarksPostgreSQL and Benchmarks
PostgreSQL and Benchmarks
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
 
Introduction to Robot Framework – Exove
Introduction to Robot Framework – ExoveIntroduction to Robot Framework – Exove
Introduction to Robot Framework – Exove
 
Spring batch introduction
Spring batch introductionSpring batch introduction
Spring batch introduction
 
OOW15 - Testing Oracle E-Business Suite Best Practices
OOW15 - Testing Oracle E-Business Suite Best PracticesOOW15 - Testing Oracle E-Business Suite Best Practices
OOW15 - Testing Oracle E-Business Suite Best Practices
 
DBA_FEATURE_USAGE_STATISTICS
DBA_FEATURE_USAGE_STATISTICSDBA_FEATURE_USAGE_STATISTICS
DBA_FEATURE_USAGE_STATISTICS
 
SQL Server Performance Tuning Baseline
SQL Server Performance Tuning BaselineSQL Server Performance Tuning Baseline
SQL Server Performance Tuning Baseline
 
Oracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleOracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration Hustle
 
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
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
 
What's new in Oracle 19c & 18c Recovery Manager (RMAN)
What's new in Oracle 19c & 18c Recovery Manager (RMAN)What's new in Oracle 19c & 18c Recovery Manager (RMAN)
What's new in Oracle 19c & 18c Recovery Manager (RMAN)
 
How We Optimize Spark SQL Jobs With parallel and sync IO
How We Optimize Spark SQL Jobs With parallel and sync IOHow We Optimize Spark SQL Jobs With parallel and sync IO
How We Optimize Spark SQL Jobs With parallel and sync IO
 
Oracle Database on Docker - Best Practices
Oracle Database on Docker - Best PracticesOracle Database on Docker - Best Practices
Oracle Database on Docker - Best Practices
 

Similaire à utPLSQL: Unit Testing for Oracle PL/SQL

SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfEric Selje
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql ServerDavid P. Moore
 
SophiaConf 2018 - P. Urso (Activeeon)
SophiaConf 2018 - P. Urso (Activeeon)SophiaConf 2018 - P. Urso (Activeeon)
SophiaConf 2018 - P. Urso (Activeeon)TelecomValley
 
Expressive Testing ...and your Code For Free?
Expressive Testing ...and your Code For Free?Expressive Testing ...and your Code For Free?
Expressive Testing ...and your Code For Free?ESUG
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It'sJim Lynch
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2Tricode (part of Dept)
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit TestingMike Lively
 
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)vilniusjug
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databasesAlessandro Alpi
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseUTC Fire & Security
 
Software Testing
Software TestingSoftware Testing
Software TestingAdroitLogic
 
Test analysis & design good practices@TDT Iasi 17Oct2013
Test analysis & design   good practices@TDT Iasi 17Oct2013Test analysis & design   good practices@TDT Iasi 17Oct2013
Test analysis & design good practices@TDT Iasi 17Oct2013Tabăra de Testare
 
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docxOverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docxhoney690131
 

Similaire à utPLSQL: Unit Testing for Oracle PL/SQL (20)

SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdf
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
Ansible testing
Ansible   testingAnsible   testing
Ansible testing
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Test Driven
Test DrivenTest Driven
Test Driven
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
 
Unit test
Unit testUnit test
Unit test
 
SophiaConf 2018 - P. Urso (Activeeon)
SophiaConf 2018 - P. Urso (Activeeon)SophiaConf 2018 - P. Urso (Activeeon)
SophiaConf 2018 - P. Urso (Activeeon)
 
TDD Training
TDD TrainingTDD Training
TDD Training
 
Expressive Testing ...and your Code For Free?
Expressive Testing ...and your Code For Free?Expressive Testing ...and your Code For Free?
Expressive Testing ...and your Code For Free?
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It's
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
utplsql.pdf
utplsql.pdfutplsql.pdf
utplsql.pdf
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
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)
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Test analysis & design good practices@TDT Iasi 17Oct2013
Test analysis & design   good practices@TDT Iasi 17Oct2013Test analysis & design   good practices@TDT Iasi 17Oct2013
Test analysis & design good practices@TDT Iasi 17Oct2013
 
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docxOverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
 

Plus de Steven Feuerstein

Six simple steps to unit testing happiness
Six simple steps to unit testing happinessSix simple steps to unit testing happiness
Six simple steps to unit testing happinessSteven Feuerstein
 
Speakers at Nov 2019 PL/SQL Office Hours session
Speakers at Nov 2019 PL/SQL Office Hours sessionSpeakers at Nov 2019 PL/SQL Office Hours session
Speakers at Nov 2019 PL/SQL Office Hours sessionSteven Feuerstein
 
New Stuff in the Oracle PL/SQL Language
New Stuff in the Oracle PL/SQL LanguageNew Stuff in the Oracle PL/SQL Language
New Stuff in the Oracle PL/SQL LanguageSteven Feuerstein
 
AskTOM Office Hours on Database Triggers
AskTOM Office Hours on Database TriggersAskTOM Office Hours on Database Triggers
AskTOM Office Hours on Database TriggersSteven Feuerstein
 
Oracle Application Express and PL/SQL: a world-class combo
Oracle Application Express and PL/SQL: a world-class comboOracle Application Express and PL/SQL: a world-class combo
Oracle Application Express and PL/SQL: a world-class comboSteven Feuerstein
 
Error Management Features of PL/SQL
Error Management Features of PL/SQLError Management Features of PL/SQL
Error Management Features of PL/SQLSteven Feuerstein
 
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 DatabaseSteven Feuerstein
 
Oracle PL/SQL 12c and 18c New Features + RADstack + Community Sites
Oracle PL/SQL 12c and 18c New Features + RADstack + Community SitesOracle PL/SQL 12c and 18c New Features + RADstack + Community Sites
Oracle PL/SQL 12c and 18c New Features + RADstack + Community SitesSteven Feuerstein
 
AskTOM Office Hours - Dynamic SQL in PL/SQL
AskTOM Office Hours - Dynamic SQL in PL/SQLAskTOM Office Hours - Dynamic SQL in PL/SQL
AskTOM Office Hours - Dynamic SQL in PL/SQLSteven Feuerstein
 
Database Developers: the most important developers on earth?
Database Developers: the most important developers on earth?Database Developers: the most important developers on earth?
Database Developers: the most important developers on earth?Steven Feuerstein
 
Impact Analysis with PL/Scope
Impact Analysis with PL/ScopeImpact Analysis with PL/Scope
Impact Analysis with PL/ScopeSteven Feuerstein
 
All About PL/SQL Collections
All About PL/SQL CollectionsAll About PL/SQL Collections
All About PL/SQL CollectionsSteven Feuerstein
 
The Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result CacheThe Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result CacheSteven Feuerstein
 
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 ProcessingSteven Feuerstein
 
Take Full Advantage of the Oracle PL/SQL Compiler
Take Full Advantage of the Oracle PL/SQL CompilerTake Full Advantage of the Oracle PL/SQL Compiler
Take Full Advantage of the Oracle PL/SQL CompilerSteven Feuerstein
 

Plus de Steven Feuerstein (19)

New(er) Stuff in PL/SQL
New(er) Stuff in PL/SQLNew(er) Stuff in PL/SQL
New(er) Stuff in PL/SQL
 
Six simple steps to unit testing happiness
Six simple steps to unit testing happinessSix simple steps to unit testing happiness
Six simple steps to unit testing happiness
 
Speakers at Nov 2019 PL/SQL Office Hours session
Speakers at Nov 2019 PL/SQL Office Hours sessionSpeakers at Nov 2019 PL/SQL Office Hours session
Speakers at Nov 2019 PL/SQL Office Hours session
 
New Stuff in the Oracle PL/SQL Language
New Stuff in the Oracle PL/SQL LanguageNew Stuff in the Oracle PL/SQL Language
New Stuff in the Oracle PL/SQL Language
 
AskTOM Office Hours on Database Triggers
AskTOM Office Hours on Database TriggersAskTOM Office Hours on Database Triggers
AskTOM Office Hours on Database Triggers
 
PL/SQL Guilty Pleasures
PL/SQL Guilty PleasuresPL/SQL Guilty Pleasures
PL/SQL Guilty Pleasures
 
Oracle Application Express and PL/SQL: a world-class combo
Oracle Application Express and PL/SQL: a world-class comboOracle Application Express and PL/SQL: a world-class combo
Oracle Application Express and PL/SQL: a world-class combo
 
Error Management Features of PL/SQL
Error Management Features of PL/SQLError Management Features of PL/SQL
Error Management Features of PL/SQL
 
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
 
OLD APEX and PL/SQL
OLD APEX and PL/SQLOLD APEX and PL/SQL
OLD APEX and PL/SQL
 
High Performance PL/SQL
High Performance PL/SQLHigh Performance PL/SQL
High Performance PL/SQL
 
Oracle PL/SQL 12c and 18c New Features + RADstack + Community Sites
Oracle PL/SQL 12c and 18c New Features + RADstack + Community SitesOracle PL/SQL 12c and 18c New Features + RADstack + Community Sites
Oracle PL/SQL 12c and 18c New Features + RADstack + Community Sites
 
AskTOM Office Hours - Dynamic SQL in PL/SQL
AskTOM Office Hours - Dynamic SQL in PL/SQLAskTOM Office Hours - Dynamic SQL in PL/SQL
AskTOM Office Hours - Dynamic SQL in PL/SQL
 
Database Developers: the most important developers on earth?
Database Developers: the most important developers on earth?Database Developers: the most important developers on earth?
Database Developers: the most important developers on earth?
 
Impact Analysis with PL/Scope
Impact Analysis with PL/ScopeImpact Analysis with PL/Scope
Impact Analysis with PL/Scope
 
All About PL/SQL Collections
All About PL/SQL CollectionsAll About PL/SQL Collections
All About PL/SQL Collections
 
The Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result CacheThe Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result Cache
 
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
 
Take Full Advantage of the Oracle PL/SQL Compiler
Take Full Advantage of the Oracle PL/SQL CompilerTake Full Advantage of the Oracle PL/SQL Compiler
Take Full Advantage of the Oracle PL/SQL Compiler
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Dernier (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

utPLSQL: Unit Testing for Oracle PL/SQL

  • 1. utPLSQL A Unit Testing Framework for Oracle PL/SQL Code Achieving PL/SQL Excellence Steven Feuerstein Original creator of utPLSQL, not currently active on project (2016) Visit the Github Repo for utPLSQL: http://https://github.com/utPLSQL
  • 2. Aw, Gee, Mom, do I have to test my code? Only if you want:  Successful applications – That is the whole point, after all.  Successful applications on time – "We don't have time to test"? Hah! Solid testing improves the chances of putting out quality code on time.  Developer and user confidence – It's a wonderful feeling to know that our code really and truly works. – Our users then love us and support us.
  • 3. Different Kinds of Tests  Functional, System, Integration tests – Written by the software customer, it answers the question “What do I need to verify before I am confident this feature works?”  Many other types of tests – Stress tests – real-world workload testing – Monkey tests – tests responses to unusual conditions – Parallel tests – compares behavior of new and old systems  And then there are unit tests... – Written by the developer, they test individual units (procedure or function in PL/SQL) The focus in this presentation.
  • 4. Wouldn't it be great if...  It was easy to construct tests – An agreed-upon and effective approach to test construction that everyone can understand and follow  It was easy to run tests – And see the results, instantly and automatically.  Testing were completely integrated into my development, QA and maintenance processes – No program goes to QA until it has passed a battery of tests – Anyone can maintain with confidence, because my test suite automatically validates my changes
  • 5. POLL  How do you (or your team) unit test your PL/SQL code today?  Possible answers: – Everyone does their own thing and we hope for the best. – Our users test our code. – We have a formal test process – We use automated testing software
  • 6. Typical Development and Testing Scenario  Let's walk through a typical development/test flow, critique it, and then take a look at how you might do the same thing with utPLSQL  We'll use a very simple example: – building an improvement to the SUBSTR function
  • 7. Improving upon SUBSTR  SUBSTR returns the sub-string specified by start position and number of characters. just10 := SUBSTR (full_string, 3, 10); Grab 10 characters staring from 3rd position  Suppose I have the starting and ending positions (or even sub- strings). How do I use SUBSTR to solve this problem? mystring := SUBSTR (full_string, 5, 17); -- start and end? Nah... mystring := SUBSTR (full_string, 5, 12); -- end – start? mystring := SUBSTR (full_string, 5, 13); -- end – start + 1? mystring := SUBSTR (full_string, 5, 11); -- end – start - 1? Grab everything between the 5th and 17th position But which of these does the job?
  • 8. A Straightforward Abstraction  Create a “between string” function that works with starting and ending positions CREATE OR REPLACE FUNCTION betwnStr ( string_in IN VARCHAR2, start_in IN INTEGER, end_in IN INTEGER ) RETURN VARCHAR2 IS BEGIN RETURN ( SUBSTR ( string_in, start_in, end_in – start_in + 1 ) ); END; myString := betwnStr (yourString, 5, 17);
  • 9. A Truly Crude Testing Technique  Let’s see…what should I check for? SQL> exec DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 3, 5)); cde And so on, and so forth...very time consuming, very haphazard...and what happens when you want to run the tests a second time?  Oh, and what about this? SQL> exec DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 0, 2)); ab  Here's a good one: SQL> exec DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 3, 100)); cdefgh
  • 10. Slightly Better: Build a Test Script  Let’s see…what should I check for? BEGIN DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 3, 5)); DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 0, 2)); DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', NULL, 5)); DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 3, NULL)); DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', 3, 100)); DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', -3, -5)); DBMS_OUTPUT.PUT_LINE (betwnstr ('abcdefgh', -3, 0)); END; / SQL> @betwnstr.tst cde ab cdefgh fgh Yielding this output: Which tells us what precisely?
  • 11. Problems with Typical Testing  Almost entirely ad hoc – No comprehensive effort to compile test cases – No infrastructure to record cases and administer tests  Difficult to verify correctness – If you wrote the program you might know that it was supposed to be “abc” or “abcd” – But what about somebody who comes along to maintain the code?  Reliance on the user community to test – Since we are never really sure we’ve tested properly, we rely on our users (or, we are lucky, the QA department) to finish our job There has got to be a better way!
  • 12. How About Extreme Programming?  "Extreme programming" sounds, well, extreme – It really isn't – It takes well-accepted ideas about programming and takes them to extremes  Resources on extreme programming: – www.xprogramming.com – www.extremeprogramming.org – Extreme Programming Explained by Kent Beck – Extreme Programming Installed by Ron Jeffries, et al – Planning Extreme Programming by Ron Jeffries, et al
  • 13. Common Sense Taken to Extremes  If code reviews are good, we'll review code all the time (pair programming)  If testing is good, everybody will test all the time (unit testing), even the customers (functional testing)  If design is good, we'll make it a part of everybody's daily business (refactoring)  If simplicity is good, we'll always leave the system with the simplest design that supports its current functionality (the simplest thing that could possibly work) A selection of extremes from XP Explained, Beck
  • 14. Extreme Unit Testing Principles  Write unit tests first!  Code a little, test a lot  Build automated red light-green light tests If testing is good, everybody will test all the time
  • 15. Write Unit Tests First  What is my program supposed to do? – By writing the test first, you concentrate more on the interface than the implementation  Write unit tests… – Before you start writing your program – Before you fix a bug (turn each bug report into a test case) – To "document" each enhancement request -- then implement All of string from starting point. Positive # greater than length of string Positive # NULLSmaller positive #Positive # NULLNULLNOT NULL NULLNULLNULL ResultEnd ValueStart Value
  • 16. Code a Little, Test a Lot  We are all in a hurry to get our coding done, but the reality is that most of our time is spent on debugging, not writing code – We need to develop our code cleaner the "first time"  Incremental development, coupled with comprehensive testing, will improve productivity and code quality simultaneously – Make small changes, then test – Add small pieces of functionality, then test – Constantly add to your test cases for the unit test
  • 17. Automated, Red Light-Green Light Tests  If we are going to build lots of tests and run them often, we need to be able to run those tests easily – This includes the setting up and cleaning up of test data and other elements – If this process is not automated, developers will not test  A developer should be able to determine at a glance whether the code passed its unit tests – Do not leave it up to the developer to analyze the results to determine the status of the tests  This is called the red-light, green-light approach – Your code does not work until you get a "green light" – 100% success
  • 18. Testing the utPLSQL Way  A unit testing “framework” for PL/SQL developers – Set of processes and code that conform to the Extreme Programming unit testing principles SQL> exec utplsql.test ('betwnstr') . > SSSS U U CCC CCC EEEEEEE SSSS SSSS > S S U U C C C C E S S S S > S U U C C C C E S S > S U U C C E S S > SSSS U U C C EEEE SSSS SSSS > S U U C C E S S > S U U C C C C E S S > S S U U C C C C E S S S S > SSSS UUU CCC CCC EEEEEEE SSSS SSSS . SUCCESS: "betwnstr"
  • 19. utPLSQL Architecture  utPLSQL is a fun demonstration of the use of dynamic SQL (really, dynamic PL/SQL) and packaged data – utPLSQL.test constructs the names of and executes the setup, unit test and teardown procedures based on the program name you provide. – utAssert populates a collection with results (failure) data ut_Setup ut_TestMe ut_Teardown utPLSQL.test Test Engine Your Test Package Results Array Test for Nulls Invalid ID Valid ID Start date too late End date too early Name unique Report Results 1 2 3 4 Assert EQ Assert NULL Assert EqTable Assertion API 5
  • 20. Steps in Using utPLSQL Step 1. Download and install utPLSQL Step 2. Choose a program to test and identify the test cases Step 3. Build a test package that incorporates those test cases Step 4. Run your test using the utPLSQL engine
  • 21. Download and Install utPLSQL  Visit http://oracle.oreilly.com/utplsql  Unzip, open up the documentation, install the utPLSQL software base, and you are ready to test – Installs in Oracle7, Oracle8 and Oracle8i – You can create a separate schema to hold utPLSQL source or install a version for each developer
  • 22. Choose Program, Define Test Cases  You can test stand-alone procedures or packages, test the entire set of programs in a package or test a subset of those programs – Start with a small program to try out the approach.  Build your grid of input values and expected outputs.  Once test cases are defined, it is time to translate them into code...the test package!
  • 23. Build a Test Package  Build a test package that contains a unit test for each program in your package  Must conform to the standard utPLSQL API: – Public setup and teardown procedures – Separate procedures for each unit test  Best approach: generate the starting point of the test package with the utGen package SQL> exec utGen.testpkg ('betwnstr'); CREATE OR REPLACE PACKAGE ut_betwnstr IS PROCEDURE ut_setup; PROCEDURE ut_teardown; PROCEDURE ut_BETWNSTR; END ut_betwnstr; / CREATE OR REPLACE PACKAGE BODY ut_betwnstr IS PROCEDURE ut_setup ... END; PROCEDURE ut_teardown ... END; PROCEDURE ut_BETWNSTR IS BEGIN utAssert.this ( 'Test of BETWNSTR', BETWNSTR( STRING_IN => '', START_IN => '', END_IN => '') ); END ut_BETWNSTR; END ut_betwnstr;
  • 24. Generate a Test Package  You can even pass an argument grid directly to utGen to generate virtually complete unit test packages. DECLARE utc VARCHAR2 (1000) := 'betwnstr|normal|abcdefgh;3;5|cde|eq betwnstr|zero start|abcdefgh;0;2|!SUBSTR(''abcdefgh'',0,2)|eq betwnstr|null start|abcdefgh;!null;2|null|isnull betwnstr|null end|abcdefgh;!3;!null|null|isnull'; BEGIN utgen.testpkg_from_string ('betwnstr', utc, output_type_in=> utgen.c_file, dir_in=> ''d:openoracleutplsqlexamples'' ); END; One line for each set of IN parameters and expected result.
  • 25. Example of Gen'd Test Code  It can take lots of code to properly test a program.  The more you can generate, the better. PROCEDURE ut_BETWNSTR IS against_this VARCHAR2(2000); check_this VARCHAR2(2000); BEGIN -- Define "control" operation for "normal" against_this := SUBSTR ('abcdefg',0,2); -- Execute test code for "normal" check_this := BETWNSTR ( STRING_IN => 'abcdefgh' , START_IN => 0 , END_IN => 2 ); -- Assert success for "normal" utAssert.eq ( 'normal', check_this, against_this ); ... 100% Generation!
  • 26. Complete Unit Test Proc  Every unit test procedure consists of three main parts (which are sometimes collapsed together, depending on the simplicity of the code being tested): – Set up the control (which might already be done with the set up procedure). – Run the code to be tested. – Compare results using the utAssert package PROCEDURE ut_del1 IS fdbk PLS_INTEGER; BEGIN /* Delete that finds no rows. */ EXECUTE IMMEDIATE ' DELETE FROM ut_DEL1 WHERE employee_id = -1'; te_employee.del ( -1, rowcount_out => fdbk); utassert.eqtable ( 'No rows deleted', 'EMPLOYEE', 'ut_DEL1'); EXCEPTION WHEN OTHERS THEN utassert.this ( 'DEL1 exception ' || SQLERRM, SQLCODE = 0 ); END; Control Test Compare Error Failure
  • 27. Apply utAssertion Validators  The utAssert offers a set of pre-defined assertion programs that test for the condition you specify and record any failures for later red light-green light reports. You can assert that: – Two scalars, tables, collections, pipes, files and queries are equal – A value is NULL or is NOT NULL – A Boolean expression is TRUE PROCEDURE ut_BETWNSTR IS BEGIN ... utAssert.eq ('Typical valid usage', BETWNSTR(STRING_IN => 'abcdefg', START_IN => 3, END_IN => 5), 'cde'); utAssert.eqFile ('Dump book data', file1, loc1, file2, loc2);
  • 28. Set up & Tear Down Test Data  The ut_setup and ut_teardown procedures manage any data structures needed to run your tests – These programs are run automatically before and after tests procedures are executed. PROCEDURE ut_teardown IS BEGIN BEGIN EXECUTE IMMEDIATE 'DROP TABLE ut_employee'; EXCEPTION WHEN OTHERS THEN NULL; END; BEGIN EXECUTE IMMEDIATE 'DROP TABLE ut_DEL1'; EXCEPTION WHEN OTHERS THEN NULL; END; ... This is an example of a portion of the tear-down used to test a table encapsulation package
  • 29. Run Your Test  Once you have built your test package, you can simply "hand it over" to utPLSQL for testing with a simple one-line call:  You can also construct test "suites" of multiple packages to test and then run that suite: SQL> exec utPLSQL.test ('betwnstr'); SQL> exec utPLSQL.testSuite ('PLVision');
  • 30. See Your Results Instantly  You are notified of success or failure – When there is a failure, you see the descriptions of failed test cases, plus information about the cause of the failure SQL> exec utplsql.test ('betwnstr') . > FFFFFFF AA III L U U RRRRR EEEEEEE > F A A I L U U R R E > F A A I L U U R R E > F A A I L U U R R E > FFFF A A I L U U RRRRRR EEEE > F AAAAAAAA I L U U R R E > F A A I L U U R R E > F A A I L U U R R E > F A A III LLLLLLL UUU R R EEEEEEE . FAILURE: "betwnstr" . UT_BETWNSTR: Typical valid usage; expected "cde", got "cd" UT_BETWNSTR: IS NULL: NULL start UT_BETWNSTR: IS NULL: End smaller than start
  • 31. Change Your Testing Ways  utPLSQL can make a dramatic difference in your ability to test and your confidence in the resulting code  With utPLSQL, you build a comprehensive "library" of unit tests as you build your application – These tests and all their test cases can be passed on to other developers – Anyone can now enhance or maintain the code with confidence. Make your changes and run the tests. If you get a green light, you're OK!
  • 32. Challenges to Using utPLSQL  Build the test packages – This can be almost as complicated as writing your application code.  Set up/change the test process in your group – It can be very difficult to move from ad-hoc testing to formal testing.  Powerful, well-designed GUI interfaces can make a big difference. – Quest is currently exploring how to support utPLSQL in its development tools.