Once the test is created in the project then we can proceed on creating TestNG.xml file for it. To do that we will need to install a plug in called "Creating TestNG XML", Go to File --> Settings or Press Ctrl+Alt+S then select Plugins and type Creating TestNG XML in search bar.
Download the plugin, once downloaded it will be available in the installed plug in section.
Now right click the class file in Project Explorer for which you wish to create XML file and select create TestNG XML from the dropdown box. On XML file will be available under Test-Output folder.
Initially the file opened will be misaligned and we need to format it. To do that go to Code --> Reformat code or Press Ctrl+Alt+L.
Inside the classes tag create a new class tag and specify the class you wish to execute on running the XML.
<classes>
<class name="Sample">
</class>
</classes>
Now Right click the XML and run the xml file, the class will be executed.