0

I have a maven project where the following classes are present:

src/main/java/App.java

src/test/java/AppTest.java

The testng.xml is under the project root. I want to trigger tests from the App.java main method using the testng.xml:

public static void main(String[] args) {
        TestNG testng = new TestNG();
        List<String> suites = Lists.newArrayList();
        suites.add("testng.xml");
        testng.setTestSuites(suites);
        testng.run();
    }

Maven project is built still I am getting errors:

Exception in thread "main" org.testng.TestNGException: Cannot find class in classpath.
Saikat
  • 14,222
  • 20
  • 104
  • 125
  • Quite similar to https://stackoverflow.com/questions/16465695/how-to-run-testng-tests-from-main-in-an-executable-jar – Saikat Dec 20 '18 at 09:20

2 Answers2

0

You can't execute java files from below main folder using testNG xml file.

src/main/java

You should include all your test files in

src/test/java

Then you can give the class name in testNG.xml file which is present in test folder. Then you would not get above error.

Chintamani Manjare
  • 1,543
  • 1
  • 13
  • 28
0

1) Steps to trace issues:

Create demo Test with following syntax and check execution:

class demo{    
  @Test
  public void testDemo(){
  System.out.println("Hello World");
  }     
}

If this has been work successfully, You have problem in your Test build structure.

Ishita Shah
  • 3,955
  • 2
  • 27
  • 51