java - How does all annotations work in TestNg without main() method -


i have doubt in testng java. completly new testng. doubt is, how test cases executing using testng in java without having main() method? please suggest me if have ideas. following code example of sample test case using testng in java. if notice, can find 1 thing there no main() method in code. then, how testcases executing?

i have doubt. main() method needed selenium webdriver , testng combination execute script? or can execute testcases without main() method? if can execute testcases without main(), how possible?

package com.first.example; import org.testng.annotations.test; public class demoone {     @test     public void firsttestcase()     {         system.out.println("im in first test case demoone class");     }      @test     public void secondtestcase()     {         system.out.println("im in second test case demoone class");     } } 

this valid doubt many testers have. because main() method needed run java program , while writing tests in testng don't use main() method, , use annotations instead.

annotations in testng lines of code can control how method below them executed. so, in short don't need write main() method, testng itself. refer code @ end in annotations documentation idea how happens.

as rightly pointed out in answer: https://stackoverflow.com/a/1918154/3619412

annotations meta-meta-objects can used describe other meta-objects. meta-objects classes, fields , methods. asking object meta-object (e.g. anobj.getclass() ) called introspection. introspection can go further , can ask meta-object annotations (e.g. aclass.getannotations). introspection , annotations belong called reflection , meta-programming.

also, it's not necessary have main() method in tests, can use main() method run testng tests if want. refer this.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -