1 / 5

What Is TestNG Annotations Its Benefits, Hierarchy & TestNG Case Priorities

What Is TestNG Annotations Its Benefits, Hierarchy & TestNG Case Priorities

Download Presentation

What Is TestNG Annotations Its Benefits, Hierarchy & TestNG Case Priorities

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What Is TestNG Annotations-Its Benefits, Hierarchy & TestNG Case Priorities? Annotationsgenerallyrepresentanoteoracommentonadiagram,etc.,toconveyitsmeaning.TestNGalsousesthemfortheexactreason.TestNGannotationsarethecodewritteninsideyoursourcetestcodelogictomanagetheflowoftheexecutionoftests? Therefore,itisvitaltoannotateyourprocessesinTestNGtoexecutethetests.TestNGwill ignoretheprocessthatdoesnotcontainanannotationsinceitwon'tknowwhentorunit.AnnotationsinTestNGcanbecomprehendedasdistinctpiecesofcodeintegratedwithinthelogicofaprogramtomanagethesequentialexecutionofthetestmethods.Inotherwords,TestNGAnnotationsassistindecidingthesequenceofthetestsmadetoexecute.TheseannotationsareextractedfromJavalanguageandareacriticalcomponentofTestNextGeneration(TestNG),anautomationframeworkthatSeleniumuses. ATestNGannotationbeginsfromthesymbol"@,"andtheannotationnamefollowsafter that.Apartfromtheheaderfileand'@'symbol,yourequirenothingtoexecuteTestNGannotations. DifferentKindsOfTestNGAnnotations • InTestNG,therearetenkindsofannotations: • @BeforeSuite-InTestNG,the@BeforeSuitemethodexecutesbeforeallothertestmethods. • @AfterSuite-InTestNG,the@AfterSuitemethodrunsafterallothertestmethods • havebeencompleted.

  2. @BeforeTest-The@BeforeTestfunctioninTestNGrunsbeforeallofthetestmethodsinthatfolderareexecuted.@BeforeTest-The@BeforeTestfunctioninTestNGrunsbeforeallofthetestmethodsinthatfolderareexecuted. • @AfterTest-TestNG's@AfterTestfunctionrunsafteralltestmethodsinafolderare • executed. • @BeforeClass-InTestNG,the@BeforeClassfunctionrunsbeforethefirstmethodcollectsthecurrentclass. • @AfterClass-InTestNG,the@AfterClassmethodiscalledafterallofthecurrent • class'stestmethodshavebeencompleted. • @BeforeMethod-InTestNG,the@BeforeMethodmethodexecutesbeforeeachtestmethod. • @AfterMethod-InTestNG,the@AfterMethodmethodexecutesaftereachtest • methodisrun. • @BeforeGroups-InTestNG,the@BeforeGroupsmethodrunsbeforethetestcasesinthatgrouprun.Itonlyexecutesonce. • @AfterGroups-The@AfterGroupsfunctioninTestNGexecutesafterthetestcases • inthatgrouphavebeenrun.Itisonlyusedonce. • TheseTestNGannotationshaveself-explanatorydefinitions.OneoftheforemostreasonstopreferTestNGisthatitisstraightforwardtolearn. • BenefitsOfTestNGAnnotations • Let'sdiscussthebenefitsofTestNGAnnotations- • TestNGannotationsaidinthecreationofacomprehensiveandcompletetestreportthatincludesinformationonthenumberoftestcasesrun,passedtestcases,failedtestcases,andskippedtestcases. • Itenablesthesimplegroupingofmultipletestcasesusingthetesting.xmlfile.Moreover,onecanprioritizetheexecutionoftestcases. • TestNGAnnotationscanimplementthesametestcasemultipletimesbyusingthe • keyword,‘invocationcount.’ • AnnotationsinTestNGareeasilyunderstandable. • TestNGAnnotationsprovidesimplecodingofteststoeliminatetherequirementforastaticprimarymethod. • TestNGassistsinthegroupingoftestcasesandtheirexecution. • TestNGofferstheabilitytoprioritizetestcasesbasedonthedemandsoftheprogrammer. • TestNGhelpstoexecutethetestcasesinaparallelmanner. • TestNGprovidesanidealwayofreportgenerationaccordingtothetestresults. • TestNGisstronglytyped,whichspecifiesthecapabilityofsoliderrorchecking. • TestNGcanalsolinktoexternaldatasources. • Toexecutetestcases,thereisnorequirementtofollowapatternorformat. • AdditionalparameterscanbepassedtoTestNGannotations. • InthecaseofTestNGannotations,thereisnorequirementtoextensionofanytestclasses. • TestNGAnnotationsarehighlytyped,whichmeansthaterrorsaredetectedatcompiletime. • HierarchyoftheTestNGAnnotations:

  3. TestNGhasalotofannotationsthathelpyouwritegoodtestsourcecodewhenyou'retestingsoftware.So,howdoesTestNGdecidewhichtestcasetorunfirst,followedbythenext,andsoon?Intheseannotations,theanswerisahierarchy.Therefore,testNGincludesahierarchyamongtheannotations.Thishierarchyisasfollows-thetopbeingthehighestpriority):TestNGhasalotofannotationsthathelpyouwritegoodtestsourcecodewhenyou'retestingsoftware.So,howdoesTestNGdecidewhichtestcasetorunfirst,followedbythenext,andsoon?Intheseannotations,theanswerisahierarchy.Therefore,testNGincludesahierarchyamongtheannotations.Thishierarchyisasfollows-thetopbeingthehighestpriority): • @BeforeSuite • @BeforeTest • @BeforeClass • @BeforeMethod • @Test • @AfterMethod • @AfterClass • @AfterTest • @AfterSuite • TestNGPrioritization • PrioritizationinTestNGisamethodtoprovideaseriestothemethodssothattheydonotexecuteoutoforder.SincealphabeticallyrunningtestcasesinTestNGhavenologicalsequence,equippingprioritytothesetestcaseshelpsusorganizeourtests'execution. • PriorityinTestNGtestcasesisaparameterwithcharacteristicvalueasapriority. • Theprioritiesareanaddedoptionthatwecanusewiththetestannotations.Thischaracteristicdeterminestheimportanceoftheannotation.ButalwaysrememberthatprioritycheckoccursaftertheannotationcheckbyTestNG.Asaresult,theTestNGannotationhierarchycomesfirst,followedbypriority-basedexecution. • ItisnecessarytoconsiderthefollowingpointsconcerningpriorityinTestNG: • Only@TestmethodscanbeusedtodefinePriorityinTestNGtestmethods. • Thetestcasemethodhasahigherprioritywhentheprioritynumberislower.

  4. PriorityinTestNGcontainsonlyintegervalues.Thevaluecanbezero,negativeorpositive.PriorityinTestNGcontainsonlyintegervalues.Thevaluecanbezero,negativeorpositive. • InTestNG,ifapriorityisdefinedindecimal,itmustfirstbeconvertedtoaninteger(throughtypecasting). • OneprocessisenabledtohaveonlyonepriorityinTestNG. • PrioritycannotpassthroughtheXMLfiles. Conclusion- TestNGAnnotationsareusedtohandlethenextmethodtobeaccomplishedinthetestscript.Itrepresentsabatchofcodeinsertedintotheprogramorbusinesslogicusedtomanagetheflowofprocessesinthetestscript. Theannotationsareveryeasytounderstandandexecute.Thereisnopredefinedformator rule,andthetesterneedstoannotatemethodsusingtheirjudgment.TheymakeSeleniumtestscriptsmoresophisticated,effective,andmanageable.Usingthemisextremelyhelpfulfortestersandmakestheirlivesmuchmoreaccessible.

More Related