You are on page 1of 7

11/6/2016

StevenFeuersteinonOraclePL/SQL:RecommendationsforunittestingPL/SQLprograms
4

Ms Siguienteblog

Crearblog Acceder

StevenFeuersteinonOraclePL/SQL
Forthelasttwentyyears,IhavemanagedtotransformanobsessionwithPL/SQLintoapayingjob.Howcool
isthat?

WEDNESDAY,MARCH11,2015

SEARCHTHISBLOG

Search

RecommendationsforunittestingPL/SQLprograms
Ihaverecentlyreceivedacoupleofrequestsforrecommendationsregardingunittestingof
PL/SQLprograms.IthoughtIwouldsharewithyouwhatItoldthem.

ABOUTME

StevenFeuerstein
Follow

First,somebackground:unittestingreferstotheprocessoftestingindividualsubprograms
forcorrectness,asopposedtooverallapplicationtesting(which,thesedays,almostalways
meansvisitingawebsite).
Thebasicideabehindunittestingisthatifyouverifythateachindividualsubprogram
workscorrectly,thenyouaremuchlesslikelytohavebugsinhigherlevelprogramsthat
callthosetestedsubprograms.Andwhenyoudo,youknowyoucanfocusonthewaythe
testedsubprogramsareused,andnotthesubprogramsthemselves.
Themostimportantapplicationofaunittestistoparticipateinaregressiontest,whichcan
beruntoverifyone'scodeworkstodayaswellasitdidyesterday.Thatwillgreatlyreduce
thechanceofyouupgradingtheapplicationanduserscomplainingthatabunchof
featuresthatworkedinV1.2nolongerworkinthefancy,newandimprovedV1.3.

482

Viewmycompleteprofile

Tweetsabout@sfonplsql
SummerScottRetweeted
StevenFeuerstein
@sfonplsql
#SQLand#PLSQLpoll:Howdoyou
format("prettyprint")your
@OracleDatabasecode?
Manually

That'salwaysembarrassing,right?
Whendeveloperstalkaboutunittesting,theyareusuallynotjusttalkingaboutwritingand
runningatest.Theyaretalkingaboutfindingandusingaframeworkthatautomatesas
muchoftheprocessaspossible.Automationiskeybecausetestingalwaystakesalotof
time,andmanualtestingtakesthemosttimeofall.

IDEbasedautoformat
3rdpartytoolnotinIDE
What,meformat?
Vote

87votes 19hoursleft

Andmostdevmanagersarenotgoingtogiveyoulotsoftimefortesting.That'sjustthe
wayitis.

Herearethemainstepsthatcouldbeautomated:

AntoanetaVatovaRetweeted

Definethetestcases:whatarethevariousscenariosthatneedtobeverified?
Thesearedrivenbyuserrequirements.
Buildthecodethatimplementsthetestcases.
Setupthedatasothatthetestcodewillrunproperly.

03Nov

StevenFeuerstein
@sfonplsql
#PLSQLvideo:Alwayslogerror(and
backtrace)beforereraisingthe
exception.buff.ly/2fciP0k

Runthetests.
Recordandexaminetheresults.
Thereareanumberofdifferenttoolsavailableforautomatedorsemiautomatedunit
testingofPL/SQLcode.Theyinclude:
1.utPLSQL:"JunitforPL/SQL",anopensourceframeworkthatIoriginallybuiltin
1999andisnowmanagedbyPaulWalker.
2.SQLDeveloperUnitTesting:Oracle'sfreePL/SQLIDEoffersintegratedunit
testing.
3.DellCodeTesterforOracle:acommercialunittestingtoolthatIoriginallydesigned
andhelpedtobuild,soldaspartoftheToadDevelopmentSuiteforOracle.
andthenabunchofothers,includingDBFit,PL/unit,PLUTOandrubyplsql,tonamea
few.IamnotgoingtopretendthatIhaveanygreatfamiliaritywiththislistof"others."I
encourageyoutocheckthemoutIamgoingtofocusontheBigThree.[Note:PL/SQL
Developer,anotherpopularPL/SQLIDEhassomeverybasicunittestingfeatures,butnot
enoughtowarrantreviewinthispost.]
Andeventhere,Iamnotgoingtoofferadetailedcomparisonoffeatures.Youwillneedto
dothatyourself,basedonyourrequirements.Instead,Iwilltakeastepbackandoffer
http://stevenfeuersteinonplsql.blogspot.com.ar/2015/03/recommendationsforunittestingplsql.html

Embed

ViewonTwitter

RESOURCES

OraclePL/SQLonOTN
PracticallyPerfectPL/SQL(Video
Channel)
OracleSQLonOTN
PL/SQLUserGuide(12.1)
PL/SQLdemonstrationscripts

POPULARPOSTS

TableFunctions,Part1:Introductionand
Exploration
Tablefunctionsfunctionsthatcanbe
calledintheFROMclauseofaqueryfrom

1/7

11/6/2016

StevenFeuersteinonOraclePL/SQL:RecommendationsforunittestingPL/SQLprograms

somehighlevelguidancetogetyoustartedonyourjourney.

utPLSQL
First,itisimportanttocorrectamisunderstandingthatsomepeoplehave,andthecreator
ofrubyplsqlrepeatsinhisblog:"StevenstoppeddevelopingfurtherutPLSQLand
currentlytherearenootheractivemaintainersofthisproject."Raimondsisabsolutely
correctthatIstoppedworkingonutPLSQLyearsago,andforawhileitdidlanguish.
Lastyear,however,PaulWalkersteppeduptotheplateandtookovermanagingthe
project.Hehasbeenapplyingbugfixes,improvingdocumentation,and
encouragingdiscussionandcollaboration.
Since2006,utPLSQLhasbeendownloadedover76,000times.Ofcourse,there'snoway
ofknowinghowmanydevteamsuseit,butIthinkitissafetosaytherearehundredsof
groupsaroundtheworldactivelyrelyingonutPLSQL.
utPLSQLisfreeandgivesyoutotalcontroloveryourtestcode.Butthat'smostlybecause
youhavetowriteallthetestcode(SQLDeveloperandCodeTestergeneratetestcodefor
you).Andthenyouhavetomaintainallthattestcode.Butonceyou'vewrittenyourtests,
builtaroundtheutPLSQLAPI,youcanexecuteyourtestswithasinglecommand,and
utPLSQLwilltellyouwhetherornotyourcodepassed(withunittesting,passingcomes
with100%correctness).
utPLSQLtestscriptscanbeintegratedintocontinuousintegrationscripting.

CodeTesterforOracle
Ithinkthatitissafetosay,evengivenmyperhapsdoublysubjectiveperspectiveof(a)
beinganoriginaldesignerofCodeTesterand(b)nowworkingfor"thecompetition"
Oracle,thatCodeTesteristhemostsophisticatedautomatedtestingtoolforPL/SQL.It's

insidetheTABLEoperatorare
fascinatingandincredibly...
Recommendationsforunit
testingPL/SQLprograms
Ihaverecentlyreceiveda
coupleofrequestsfor
recommendationsregarding
unittestingofPL/SQLprograms.Ithought
Iwouldsharewithyo...
27HoursofFreePL/SQL
VideoTrainingatPL/SQL
Channel
[June2016update:PL/SQL
Channelvideoshavebeen
movedtothenewPracticallyPerfect
PL/SQLchannelonYouTube.The
PL/SQLChannelhas...
TableFunctions,Part5a:An
introductiontopipelined
tablefunctions
[Gee,thatwas
embarrassing.Istartaseries
ontablefunctions,andthenitfaltersand
stops.MyapologiesIgotsobusyeating
anddri...
Dealingwith"PLS306:Wrongnumberor
typesofarguments"acrossschemas
ThePLS306compileerrorcanbeareal
painintheyouknowwhat.Thereare
manypossiblecauses,includingtypoin
namewithnamednotatio...
LintCheckersforPL/SQL
Receivedthisquestion
today:"Istherea
commercialtoolavailablefor
scanningPL/SQLcodeand
providingfeedbackonadherencetoco...

packedfulloffeatures,handleslotsofcomplexscenarios(forexample,ifyourparameteris
acollectionofrecordsandtherecordcontainsacollectionofobjects,youcan
rightinsidetheUIprovidevaluesforthatparameter),generatestestcodefromyour
specifications,andofferslimitedintegrationwithToad.
Thatsophisticationcomes,however,atasteepprice,namely$2854fortheToad
DevelopmentSuiteforOracle.Youcan'tbuyCodeTesterbyitself.
Sohere'smyrecommendation:ifyouarelicensedtousetheToadDevelopmentSuitefor
Oracle(evenifyouonlyuseToad,youmayhavealicensetoTDSOviaasitelicense,and
notevenknowit),youoweittoyourselfandyourteamtocheckoutCodeTester.
Youwilllikelyrunintosomefrustrationsandlimitations,butitdoesanawfullotoftheheavy
liftingforyou.
CodeTestertestscanbeintegratedintocontinuousintegrationscriptingviaaPL/SQLAPI.

SQLDeveloperUnitTesting
Lastanddefinitelynotleast,istheunittestingfeatureintegrateddirectlyintoSQL
Developer.Let'sstoprighttheretomakesureyouappreciatewhatIjustsaid:

PL/SQL101:Whycan'tI
displayaBooleanvaluewith
DBMS_OUTPUT.PUT_LINE?
DBMS_OUTPUT.PUT_LINE
isthebuiltinprocedurethat
PL/SQLdevelopersusetodisplayoutput
onthescreen.Let'swatchitdoit's...
ThefutureofOraclePL/SQL:
somethoughtsonSten
Vesterli'sthoughts
StenVesterlipublisheda
verythoughtprovokingpost
onhisblog:Pleasestopreadingthispost,
andreadthatone.Whenyouaredo...
MostimportantPL/SQLcodingstandards?
Receivedthisrequesttodayviaemail:I
wasattheMOUGFallConferencein
Chicagoafewweeksagoandenjoyed
yourpresentationonther...
YesSQL!acelebrationofSQLand
PL/SQL:OOW14event29September
Firstthekeydetails:When:6:308:00
PMonMonday,29SeptemberWhere:
MosconeSouth103Toregister:Session
CON9027.Thiseven...

TheautomatedunittestingfeatureofSQLDeveloperisnotaseparatetoolfromtheeditor
(whichisthecasewithCodeTesteritisexternaltoToad,withonlyminimalintegration

BLOGARCHIVE

points).ItisapartofSQLDeveloper.Thisis,Ibelieveacrucialpoint,becausedevelopers

2016(52)

donotliketoleavetheireditors.Instead,theywantallnecessaryfunctionalitybroughtto

2015(68)

theminsidetheireditors.

December(3)
November(4)

Hereisonescreenshotfromthedoctogiveyouasenseoftheintegration:

http://stevenfeuersteinonplsql.blogspot.com.ar/2015/03/recommendationsforunittestingplsql.html

October(2)

2/7

11/6/2016

StevenFeuersteinonOraclePL/SQL:RecommendationsforunittestingPL/SQLprograms
September(4)
August(5)
July(8)
June(8)
May(5)
April(9)
March(7)
Codecleanup:postauthenticationin
ApplicationE...
Don'tWanttoRememberNo
StinkingErrorCodes
Recommendationsforunittesting
PL/SQLprograms

Inmanyways,SQLDeveloperUnitTestingandCodeTesterforOraclearesimilar.They
bothaimtotaketheburdenoffofyouforwritingtestcode.Instead,youdescribethetest
case:Whataretheinputvalues?Whatdataneedstobesetup?Mostimportantly,what
aretheexpectedoutcomes?
SQLDeveloperthengeneratescodethatimplementsyourtestcase.Ifyouneedto
changethetest,youdon'thavetomodifytestcode(asyouwoulddowithutPLSQL),you
gointotheUI,makeachange,andrunyourtestagain.

27HoursofFreePL/SQLVideo
TrainingatPL/SQLC...
LookingforAnotherOracle
DeveloperAdvocatefor...
Ohthosetrickyexceptionsections!
Whywon'tith...
MiningtheOracleDatabaseforCool
AppdevFeature...
February(8)

SQLDevunittestscanalsobeintegratedintocontinuousintegrationscripting.
Sohere'smyrecommendation:

January(5)
2014(40)

IfyouarealreadyusingSQLDeveloper,thedecisionshouldbeclear.Trytheintegrated
unittestingfeatures.Seeifitmeetsyourneeds(atleastenoughtogetyougoing,building
sometests,experiencingthepositivefeedbackloop).
IfyouarenotaSQLDeveloperuser,let'ssayyouuseToadorPL/SQLDeveloper,and
youarenotlikelytogetaccesstoCodeTesterforOracle,thenIalsosuggestyouinstall
SQLDeveloperandtryitsunittestingfeatures.Sure,itwouldbebettertojustuseone
IDE,butiftheautomatedtestingofSQLDevworksforyou,givenitsinfinitelylowcost(as
in,free),IwouldthinkyoucouldjustifyhavingthatsecondIDEaroundsolelyfortesting.

OverallConclusions
IfyouhaveaccesstoanIDEthatoffersautomatedunittesting,includingthegenerationof
testcodefromtestcasespecifications,trythatfirst.Theproductivitygainsoftestcode
generationaresomassive,itcaneasilybeworthacceptingsomelimitations.
IfyouareallergictoUIbasedtestingand/orworryaboutbeingconstrainedbyanIDE's
featureset(inotherwords,youareacommandlinefanatic),utPLSQLoffersapowerful
alternative.It'sproventobeusefultohundredsandmaybethousandsofdevteamsover
theyears.Itisanactivelymaintainedandenhancedopensourceproject.

YourExperience?
DoyouuseanautomatedtestingframeworkforPL/SQL?Orhaveyoubuiltyourown?
Pleasetellusaboutyourownexperience.

PostedbyStevenFeuersteinat8:40AM
+4 Recommend this on Google

Labels:oracle,pl/sql,testing,unittesting

22comments:
KevanGelling March11,2015at9:37AM
IlikeSQLDeveloperUnitTesting.Withafewworkaroundsandalotofpatience,it's
averyabletoolforcollatingandrunningtests.

http://stevenfeuersteinonplsql.blogspot.com.ar/2015/03/recommendationsforunittestingplsql.html

3/7

11/6/2016

StevenFeuersteinonOraclePL/SQL:RecommendationsforunittestingPL/SQLprograms
SDUT(?)justneedsalittlebitoflovefromthedevelopmentteam.Maybeyoucould
haveaword)
Reply

StevenFeuerstein

March11,2015at9:56AM

Thanks,Kevan.Canyougivemeanyspecificsregardingperhapsthetopthreebits
ofloveyou'dliketosee?
Reply

Drumbeg March11,2015at1:21PM
I'veusedutPLSQLforacoupleofyearsextensivelyanditreallyhelpedmetogetto
grips with unit testing. I loved not being tied into an IDE (we ran the tests from
Eclipse).Weevenextendedtheframeworkwithourownassertions.
Reply

Micke March11,2015at1:54PM
Last year we switched from Code Tester to utPLSQL. We tried Code Tester for
several years but somehow it did not help us with getting a true TDD process in
developingPLSQLlogic.Changingthesignatureofafunctionormovingittoother
packages caused real headaches. Since we have mostly java developers in our
team, utPLSQL felt more natural. With utPLSQL we also lifted our automatic
databaseteststoanhigherlevel.Itisreallyeasytowritetestcasesandassertions
ontheintegrationofpackagesandothercodeunitswithutPLSQL.Wetriedthiswith
CodeTesterbutwedidn'tsucceed.
Reply

StevenFeuerstein

March12,2015at3:29AM

AndanotereceivedfromDennisV:
we have integrated dell code tester with Jenkins to have a continuous integration
test. it save a lot of bug fixing in released versions. and also helps us to have a
application that is backward compatible. what is a big benefit for our customers.
#adaption
Reply

KevanGelling March12,2015at5:04AM
CanIhave4?
1.SubfoldersunderTeststohelpmanagemultipletests.
2. Move the Parameters and Process Validation windows to the top of the edit
screen(ormakeStartupandTeardownwindowscollapsible).
3.Add'copyimplementation'
4. Use the SQL Developerlike code editor (with syntax highlighting, code
completion,etc.)forediting
Reply
Replies
Anonymous July29,2015at10:33PM
+1forallthese
Reply

StevenFeuerstein

March12,2015at5:09AM

Kevan,IwillmakesureJeffSmithseesthis,butIsuggestyoualsoconsiderposting
these as ideas on the SQL Dev Exchange or maybe you already did that?
https://apex.oracle.com/pls/apex/f?p=43135:1
Reply

Anonymous March13,2015at12:34AM

http://stevenfeuersteinonplsql.blogspot.com.ar/2015/03/recommendationsforunittestingplsql.html

4/7

11/6/2016

StevenFeuersteinonOraclePL/SQL:RecommendationsforunittestingPL/SQLprograms
IuseutPLSQLtheautomatictestingofcode.Startusingwerenoteasy,buttodayit
istestingafixedpartofthedevelopmentcycle.
B.Vetrak
Reply

Amit March13,2015at3:05PM
Hi Steve, Thanks for putting this up. SQL developer has scope for
improvement...http://www.fuzzy.cz/en/articles/unittestingplsqlcodeinsqldeveloper
problems/
...untilthenutplsqlitis.
Reply

Anonymous May15,2015at2:01AM
HiSteven,
thanksforthisgoodarticle,igotacoupleofquestions,andIreallyhopeyougotthe
answer:
istheresomebestpractiseabouthowtodesignprocedureandfunctioninorderto
make it easy for testing ? in all the ex provided by utplsql, all the examples are
testing basic algorithm that doesn't need any access to database, there's no
dependency on table content. i'm working in a big project where almost every
procedure, every function is based on tables content, ( we are dealing with more
than one thousand table, to be more specific, it's a financial application ), my
question is, what's the best approache to be able to test this kind of function and
procedurewherethebodyofthef/pdependsonthedatabasecontentandtheuser
setup?iwasthinkingaboutusinganotherschemadedicatedfortesting,wherethe
thesetupfunctionwillsetupanythingonthatschemathatisneededforthetesting
and then rollback it once the testing finishes, please let me know if you you have
any good url or book that would be helpful and that talks about the same subject,
againmanythanksforyourvaluablearticlesandsupport.
Reply

Anonymous January7,2016at6:04AM
HiSteven,
Iamunabletoseetheobjectsafterconnectedtothecodetester.Myconnectionis
showingsuccessfullyconnected.Couldyoupleasehelpmeonthis.
Thanks&Regards,
Gangadhar
Reply

StevenFeuerstein

January7,2016at6:33AM

Gangadhar, I suggest you report the issue to Dell Support or go to ToadWorld.com


andseeifyoucanfindaplacetheretoaskaquestionaboutCodeTester.
Reply

swapnali January15,2016at8:42AM
Hi,
Veryinformativeblogimustsay.
Ijusthaveaquickquestiondoessqldeveloperunittestingsupport%rowtypedata
typesasinputoroutputfromafunction/procedure?
Reply

StevenFeuerstein

January21,2016at7:42AM

@swapnali, thanks glad it was useful. Answer to your question: no, %rowtype and
recordargumentsarenotyetsupported.
Reply

Anonymous April29,2016at11:14AM

http://stevenfeuersteinonplsql.blogspot.com.ar/2015/03/recommendationsforunittestingplsql.html

5/7

11/6/2016

StevenFeuersteinonOraclePL/SQL:RecommendationsforunittestingPL/SQLprograms
Aftertryingmanytestingframeworks,allofthosewetriedwerementionedhere,we
picked and love Ruby plsqlspec. That was more than 5 years ago. It's integration
with Oracle EBS makesit even better for our shop. plsqlspec allows us to perform
small unit tests to larger integration tests like creating POs and invoices and then
matchingquickly.
KeeppushingTDD!
Thanks,
Jason
Reply

Anonymous April29,2016at11:18AM
I should have also mentioned how easy it is to automate the plsqlspec tests by
addingthemtoacontinuousintegrationserverlikeHudson.
AndtheaddedbenefitofusingalanguagelikeRubythatisajoytoprogramin.
Reply

StevenFeuerstein

May1,2016at11:18AM

Thanks,Jason.Veryinteresting!IimagineformanyPL/SQLdeveloperstheideaof
learning ruby is rather offputting in terms of leveraging this framework. Any
suggestions for a fast, easy path to having enough ruby knowledge to use plsql
spec?
Reply
Replies
Anonymous May1,2016at3:18PM
Whatyousayissadbuttrue.Learninganotherlanguagejusttotestyour
PL/SQLcodecanputsomepeopleoff.But,inmyopinion,thebenefitsfar
outweigh any costs. Also, you just need the Ruby basics which a
developershouldbeabletopickupveryquicklyfromanynumberofsites
andbooks.

Onecaveat(formyslowbrain)isthattheheavilyusedblockfunctionality
in Ruby may take a solely PL/SQL developer a bit of brain retraining but
other than that Ruby is a very straight forward language that is designed
around the concept of least astonishment. You won't get the hmmm, I
recallthereare3kindsofarraysinPL/SQL,whichoneshouldIusenowor
hmm,nowI'musingPL/SQLobjecttypesandneedtoaccessSQLtypes
where's that noman's land between SQL types and object types where
they havne't built the bridge and I can't get there from here types of
questions.

Learning a different language will exercise that brain and put it into a
highergear.Likeplayingthosepuzzlegamesyourecommend.

We PL/SQL developers must realize that we cannot write everything in


PL/SQL.EvenwithApex,whichIreallylikeBTW(CheckoutSeleniumfor
testingWebUI'susingRSpec).Maybeit'sabiteasierwhendevelopingfor
Oracle EBS since the tech stack is so large. You already need to know
shell scripting, some perl, PL/SQL, of course, Java, and even Pro*C was
helpful ten years ago. Now we are in or entering the post Java era and
Groovyismakingit'swayintothestack.Sowhat'sanothersyntax?

MaybesomedayOraclewillaskRaimondstopresentonplsqlspecforthe
goodofPL/SQLdevelopersandnotbaseduponwhetheritcompeteswith
OATS or some other pay for Oracle product. I've submitted to present on
plsqlspecmultipletimesforOOWbutnevergotthegreenlight.SoI'mnot
holdingmybreath.

AllIcansayisthatinmyopinionPL/SQLdevelopersneedtoemployTDD
andbeopenaboutchoosingthebestoptionsfordoingso.Onceyousee
how much better TDD is for the quality of the software you deliver you
won't go back and adding methods to your PL/SQL package procedures
and functions the way plsqlspec allows feels quite natural and is really
coolinmyopinion!

Keepupthegreatworkofspreadingthewordontesting.
Reply

http://stevenfeuersteinonplsql.blogspot.com.ar/2015/03/recommendationsforunittestingplsql.html

6/7

11/6/2016

StevenFeuersteinonOraclePL/SQL:RecommendationsforunittestingPL/SQLprograms

DanielleFelder August16,2016at11:48PM
Nice post. Your readers might also find real user reviews for Oracle SQL Developer
on IT Central Station to be helpful. As an example, this user writes that one
particularly valuable feature is, "Oracle SQL Developer Data Modeler. No PL/SQL
IDEhassuchmodellingcapabilities,asfarasIknow.Thisisakillerfeatureforme."
Youcanreadtherestofhisreviewhere:https://goo.gl/MG3nQH.
Reply

AnilKumarD November4,2016at11:40AM
RightnowSDUTdoesnotsupportREFCursorsand%ROWTYPEasparameters.Is
thereaworkaroundforthis,otherthanwritingsomewrapperprocedure?
Reply
Replies
StevenFeuerstein

November4,2016at11:41AM

NotthatIknowof,Anil.
Reply

Enteryourcomment...

Commentas:

Publish

Selectprofile...

Preview

NewerPost

Home

OlderPost

Subscribeto:PostComments(Atom)

PictureWindowtemplate.PoweredbyBlogger.

http://stevenfeuersteinonplsql.blogspot.com.ar/2015/03/recommendationsforunittestingplsql.html

7/7

You might also like