I've got similar problem. The reason for that was "Scope" option of "testng" dependency set to "test" when "compile" was needed.
How I fixed it (note, I used Eclipse):
- Open pom.xml file.
- Go to "Dependencies" tab.
- Select "testng" package and click on "Properties..."
- On opened screen change "Scope" option to "compile" and click "OK" to save it.
- Try to build your project again with "compile test" goals.
Videos
I've got similar problem. The reason for that was "Scope" option of "testng" dependency set to "test" when "compile" was needed.
How I fixed it (note, I used Eclipse):
- Open pom.xml file.
- Go to "Dependencies" tab.
- Select "testng" package and click on "Properties..."
- On opened screen change "Scope" option to "compile" and click "OK" to save it.
- Try to build your project again with "compile test" goals.
remove test scope testng dependency and add compile
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
<scope>compile</scope>
</dependency>
It works for me. Make sure you have added dependency for the correct Maven module into dependencies section. After this make sure you have re-imported project in Maven tool window:

Initially I had the same problem when I copy artifacts from https://mvnrepository.com/artifact/org.testng/testng/7.3.0 and paste the code on my IntelliJ it was showing the errors, Once I have Reload from Disk(right click on project it will show the option) it was showing refresh option on the right side of the screen, once I refreshed it the error was resolved.