I am fairly beginner in TestNG, Maven & IntelliJ. I have created a new maven project and defined a 'runtest' class under src/main/java. I am able to run testcases through testng.xml if I specify test classes under src/main/java.
However, I want to specify my test classes inside src/test/java. If I specify any test class 'test1.java' under src/test/java and run, it gives error : Error: Cannot find class in classpath: java/test1
Workarounds I already tried:
- In testng.xml file, giving full path of the test case - starting from /Users/ (Note: I am using MAC)
- In testng.xml file, giving full path of the test case - starting from src/
- Specified additional classpath in pom.xml under maven-surefire-plugin (over here also I specified full path, path from project base directory etc.)
- I tried to clear cache, however no difference
Other observations:
Intellij shows me an error when I specify path in testng.xml file. It gives me options to create class XXXX. When I click on create class - it gives me 2 locations (src/main/java & src/test/java). I already have respective test class under src/test/java. Why is it not accepting?
I tried to check my classpath in Mac, but I'm not having much success.
Any help will be appreciated.
Thanks
Based on comments, editing my questions. Specifying my code details.
I want to call testng.xml file from TestNG class. Here is my TestNG Class: runtests.java in src/main/java
public static TestNG testng;
public static void main(String[] args) {
try {
testng = new TestNG();
testng.setPreserveOrder(true);
testng.setVerbose(0);
testng.setTestSuites(Arrays.asList("config/testng.xml"));
testng.run();
}
catch (Exception e) {
//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
The reason I want to do this way is, I want to create maven build and I want to specify testng.xml editable to user. So, if someone wants to run just 1 test case, they can edit testng.xml and run only 1 test case.
Here is my testng.xml in config/testng.xml
suite name="Testing" verbose="0"
test name="Test1"
classes
class name="java/test1"
classes
test
over here in the class name, I am not able to add classes from other location. I am only able to specify classes mentioned in src/main/java. I want to specify classes mentioned in src/test/java.
One more thing, I want to do is: I want to create one configuration file, that will go with build and will be editable. So, if user wants to edit configutation (i.e. change server name etc.) user can edit configuration file and run test cases.