NOTE: I found a solution. I've moved my Main.class from src/main/java to src/test/java where all my test classes are. Still, how can I reference classes that are in different folders (src and test)?
I want to run my Tests Suite (.xml) through the Main.class. I can run it directly by right clicking the .xml inside eclipse and choosing "Run as -> TestNG" but when I try running it through main it will throw an error "Cannot find class in classpath: app.tva.tests.LoginTest".
This is what I have on my Main.class:
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add("SuitesTest\\TVASuite.xml");
testng.setTestSuites(suites);
testng.run();
And this is what I have inside my xml:
<suite name="TVA Suite">
<parameter name="app" value="tva" />
<listeners>
<listener class-name="app.common.listeners.TestListener" />
<listener class-name="app.common.listeners.AnnotationTransformer"/>
</listeners>
<test name="TVA Test">
<classes>
<class name="app.tva.tests.LoginTest" />
</classes>
</test>
try something like
List<String> testFilesList = new ArrayList<String>();
testFilesList.add("./testng.xml"); //test suite resides in the working directory's root folder
**testng.setTestSuites(testFilesList);** //you can addd multiple suites either here by adding multiple files or include all suites needed in the testng.xml file
testng.setUseDefaultListeners(false);
testng.addListener(htmlRep);
testng.run();
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.