简体   繁体   中英

org.testng.TestNGException Cannot find class in classpath

I have a maven project where following classes are present:

src/main/java/App.java

src/test/java/AppTest.java

The testng.xml is under project root. I want to trigger tests from 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 error: Exception in thread "main" org.testng.TestNGException: Cannot find class in classpath .

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM