Hi,
TestNG can be invoked in several ways: Command Line, TestNG Runner plugin, Run option above Test method, IDE Run options: Eclipse, IntelliJ IDEA, Ant.
TestNG xml file has its own benefits that can be very useful for testers. Please take a look at this article for the added advantages of testng.xml file https://www.programsbuzz.com/article/selenium-use-testng-xml-file
Source: ProgramsBuzz Youtube
Video Title: Cucumber JUnit: Perform BeforeSuite or BeforeAll Operations
Video URL: https://youtu.be/PVcO-KDo6D4
Query
Umang Sharma: ProgramsBuzz one more thing Tarun, just a silly question. Do we always need to create a testNG.xml file to run test cases when we use TestNG as a unit test framework? can't we just directly trigger the tests by running testrunner class? Do we see any added advantage of using the testng.xml file to trigger tests? Any info on this will be of great help!