Automating Eclipse PDE Unit Tests using AntWord文件下载.docx
- 文档编号:8389745
- 上传时间:2023-05-11
- 格式:DOCX
- 页数:14
- 大小:125.25KB
Automating Eclipse PDE Unit Tests using AntWord文件下载.docx
《Automating Eclipse PDE Unit Tests using AntWord文件下载.docx》由会员分享,可在线阅读,更多相关《Automating Eclipse PDE Unit Tests using AntWord文件下载.docx(14页珍藏版)》请在冰点文库上搜索。
tberunatall,andteststhatarenotrunarenexttouseless.
TheEclipsePlug-inDevelopmentEnvironment(PDE)providesaexcellentframeworkfordevelopingplug-insandalsoprovidesfacilitiestowriteandrunPDEunittestsforyourplug-insthatcanberunfromwithintheEclipseenvironment.
OnceyouhavetakenthetimeandefforttowritethesevaluablePDEunittests,howdoyouautomatetherunningofthesePDEunittestssothatyoucanintegratethemintoyourautomatedbuild?
SearchingthewebprovidesseveraloptionsforautomatingPDEtestssuchas:
∙MarkusBarchfeld'
sexcellent
BuildandTestAutomationforplug-insandfeatures
articlewhichdetailssettingupautomaticbuildingandtestingforanEclipseplug-inusingtheEclipseheadlessbuild.
∙EclipseTestFramework.
∙PatrickPaulin'
sRCPQuickstartposton
RunningAutomatedTestswithPDEBuild.
∙Somemoreexcellentlinkscanbefoundat
6GreatLinksforEclipseBuildAutomationwithPDEBuild.
AsyoucanseewritingPDETestscanbecomplex,runningPDETestsfromthecommandlinecanbecomplextoo,butrunningthemandcollectingtheresultsinaformatthatcanbeeasilyinterpreted(e.g.Junitreportformat)isevenmoredifficult.
Thisarticleprovidesadetailedexampleapplication,theenablingtechnologytocollectandformattestresults(see
PDETestUtilities
),andabuildsystemthatdemonstratesagenericmechanismforrunningPDETestsusingAnt,allowingyoutointegrateitwithanyAntbuildsystem.
ThisPDETesttechniqueprovidesthefollowingbenefits:
1.AllowsyoutorunyourPDETestsfromthecommandline
2.AllowsyoutocollectthePDETestsresultsinaformatthatcanbeeasilyinterpreted(i.e.Junitreportformat)
3.AllowsyoutointegratePDETestsintoanyAnt-basedbuildsystem
Note:
allthetechniquesandexamplesdetailedinthisarticlehavebeentestedagainstEclipse3.3(specificallyEclipse3.3.2and3.3.1.1)onWindowsXPonlyandusing
Ant1.7.0
.Thereisalsoan
Eclipse3.1version
oftheexamplecode.
Overview
PDEunittestsareautomatedasfollows:
Prerequisites:
1.AdedicatedPDEtestEclipseinstallationthatisonlyusedbytheautomatedbuildsystem.
2.ForeachEclipseplug-in
A
thatistobetested,anEclipseplug-infragment
A-test
for
thatonlycontainsthePDEunittestsandtheirtestdependenciesfortheplug-in
A.
3.Apre-defined(orspecified)PDEtestport.
4.APDEtestlistenerclasstolistenonthePDEtestportfortheresultsfromthePDEtestrun.
5.AlistofPDEtestclassestoberunaspartofthePDETestrun
RunningthePDEunittests:
See
Figure1
belowforavisualrepresentationofthePDEteststeps.
1.Deployplug-in
andplug-infragment
intoapristinePDEtestEclipseinstallation.
2.SelectPDEtestport(orusepredefinedreservedport).
3.StartthePDEtestlistenerprocessthatlistensonthePDEtestport.StartupthePDEtestEclipseinstallation,specifyingthelistofunittestclassestoberun,andthePDEtestporttooutputtestprogressandresultsto.
4.ThePDEtestEclipseinstallationstartsupandautomaticallyrunsthespecifiedtestsandoutputstheresultstothePDEtestportwherethePDEtestlistenerprocesscapturestheresultsandoutputstheminstandardAnt
junit
taskXMLformat.
5.RuntheregularAnt
junitreport
taskonthegeneratedtestresultsXMLfiles.
6.That'
sit:
younowhaveatypicalAntJUnitHTMLreportcontainingyourPDEunittestresults.
Figure1-OverviewdiagramofthePDETeststeps
Prerequisites
Thissectiondescribestheprerequisitesforusingthistechniqueinmoredetail.
DedicatedPDEtestEclipseinstallation
InordertorunthePDETestsyouneedaseparateEclipseinstallationwhosesolepurposeisforrunningthePDETests.HavingadedicatedEclipseinstallationprovidesapristineandrepeatabletestenvironmentandavoidsanypossibleconflictsorcorruptionthatmightoccurwithatypicaldevelopmentEclipseinstallation.
UseanEclipseplug-infragmentforthePDEUnitTestsforaplug-in
Thistechniquepromotestheuseof
Eclipseplug-infragments
todevelopPDEUnittestsforplug-ins,soforeachEclipseplug-in
Athatistobetested,anEclipseplug-infragment
YoucanofcoursedevelopthePDEtestsdirectlyintheplug-in(inatestdirectory),butthiscanleadtounwanteddependenciesinyourplug-inandinvolvesslightlymorecomplicatedpackagingforyourplug-in(i.e.withouttestclassesandtestdependencies).
TheEclipseplug-infragmentapproachavoidsthesepitfallsandalthoughitrequiresalittlemoresetupinitiallyitprovidesacleanerandclearermechanismfordefiningPDETestsandalsoprovidesastraightforwardwayforthebuildsystemofidentifyingwhichplug-inshavePDETestsassociatedwiththem.
ForagooddescriptionandmoregeneraldiscussionofusingEclipseplug-infragmentsfortesting,seePatrickPaulin'
sRCPQuickstartarticle
TestingPlug-inswithFragments.
PDEtestport
InorderforthePDEtestrunnerandthePDEtestlistenerprocessestocommunicate,bothprocessesneedtouseapredefinedorspecifiedportsothatthePDEtestrunnercansendthetestprogressandresultstothePDEtestlistenerprocess.Intheexamplecodeweuseautilityclass
pde.test.utils.PDETestPortLocator
inthe
pde.test.utils
plug-intofindanavailableportandthisisusedbythePDEtestrunnerandPDEtestlistenerprocessestocommunicate.
PDEtestlistenerprocess
InordertobeabletomonitorandrecordtheprogressandresultsofthePDEtestrun,youneedaPDEtestlistenerprocessthatlistensonthespecifiedporttocollectPDEtestprogressandresultsfromthePDEtestrunnerprocess.IdeallythePDEtestlistenerprocessshouldprovidetheresultsofthePDEtestruninamannerthatiseasytointerpretshouldanyofthetestsfail.
The
pde.test.utils.PDETestResultsCollector
class(usingthe
pde.test.utils.PDETestListener
class)inthe
plug-in,providesthePDEtestlistenerprocessthatlistensonthespecifedportfortestresultsfromthePDEtestrunnerprocessandhandlesthemusingthe
org.apache.tools.ant.taskdefs.optional.junit.JUnitTest
andorg.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter
classes(availablefromApacheAntAPI)toprovidetheresultsinthesameXMLformatthatisoutputbytheAnt
task.TheseXMLresultfilescanthenbeusedbytheAnt
tasktoprovidean
HTMLreport
ofthePDEtestrunthatisveryeasilyinterpreted.
ForexampletorunthePDEtestlistenerprocessfromthecommandlineforourexamplePDEtestswouldsimilarto:
java-classpath...pde.test.utils.PDETestResultsCollectorPhoneBookExample-test1623
PDEtestrunnerprocess
EclipseprovidesamechanismforrunningtestsfromthecommandlineusingthemainEclipselauncherclasstolaunchtheorg.eclipse.pde.junit.runtime.uitestapplication
application,thisisthePDEtestrunnerprocess.ThePDEtestrunnerprocessispasseddetailsoftheporttopublishtestprogressandresultstoforlistenerstoanalyse,theplug-innamebeingtestedandthenamesofthePDEtestclassestorun.
ForexampletorunthePDEtestrunnerprocessfromthecommandlineforourexamplePDEtestswouldsimilarto:
java-classpath...\eclipse\plugins\org.eclipse.equinox.launcher_1.0.1.R33x_v20080118.jar
org.eclipse.equinox.launcher.Main
-applicationorg.eclipse.pde.junit.runtime.uitestapplication
-data...\PhoneBookExample-test\target\reports\test/output/ws
-devbin
-clean
-port1623
-testpluginnamePhoneBookExample
-classnamesphonebookexample.dialogs.PhoneBookEntryEditorDialogTest
PDETestsclasseslist
ThePDEtestrunnerprocesstakesasaparameteracommaseparatedlistofthetestclassestoruninaPDEtestrun.Intheexamplecode,thenameofthesingletestclasstoberunishardcodedi.e.
phonebookexample.dialogs.PhoneBookEntryEditorDialogTest
butthegenerationofthelistofPDEtestclassescouldeasilybeautomated.
RunningPDEUnitTestsinAnt
ThissectiondescribestheAntbuildfileintheexamplecodethatrunsthePDETestsandexplainsthekeyAnttargetsinvolved.SeeFigure1
aboveforavisualrepresentationofthestepsinvolvedinrunningPDEtestsinAnt.
TheexamplecodefeaturingfullsourceandAntbuildfilesforaprojectcontainingPDEunittestscanbefoundintheaccompanyingPDETestExampleProjects-3.3.zip
ZIPfile.
thatthe
PDETestExampleProjects-3.3.zip
ZIPfilecontainsafullstandaloneprojectcompletewithanAntbuildsystem(seezipcontents
belowformoredetails).UnzipthecontentsintoadirectorythatisseparatefromyourEclipseinstallationandworkspace.
AntscriptthatrunsPDEUnittests
ThefollowingAntexcerptisfromtheAntbuildfileusedtorunthePDEunittestsinthe
PhoneBookExample-test
plug-infragmentforthe
PhoneBookExample
plug-in(see
projects\PhoneBook
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Automating Eclipse PDE Unit Tests using Ant
链接地址:https://www.bingdoc.com/p-8389745.html