Please follow the below steps, these worked well for me in Eclipse.
Right-click on your project in the Project Explorer.
Select Build Path → Configure Build Path.
In the Libraries tab:
Ensure the TestNG library is listed and checked.
If it’s missing, click Add Library → TestNG → Next → Finish.
Switch to the Order and Export tab:
Check the box next to the TestNG library.
Move TestNG to the top of the list.
Also ensure the JRE System Library is added and points to a valid JDK (Java Development Kit), not just the JRE.
Click Apply, then OK to save the changes.
Right-click the project again and select Maven → Update Project.
Run a Maven install to ensure dependencies are resolved:
Run As → Maven install
Finally, run your class as a TestNG Test:
Right-click → Run As → TestNG Test
Happy Coding!! Cheers!