可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
When i'm trying to run the test suite, am getting this exception. We are using maven project here and i am done with refreshing, cleaning, reinstalling testNG and then imported the maven projects but then also am getting the same exception. Please suggest any ways that am missing here.
Error console:
org.testng.TestNGException:
Cannot find class in classpath: EmpClass
at org.testng.xml.XmlClass.loadClass(XmlClass.java:81)
at org.testng.xml.XmlClass.init(XmlClass.java:73)
at org.testng.xml.XmlClass.<init>(XmlClass.java:59)
at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:543)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:766)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1350)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2778)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:333)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at org.testng.xml.XMLParser.parse(XMLParser.java:39)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
at org.testng.xml.Parser.parse(Parser.java:168)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
回答1:
I also got the same exception:
I tried the following steps:
In Eclipse> Project > Clean. (The Exception remained)
I ran another project(The testng.xml ran successfully)
After running another project, I ran the project in which I was getting the Exception, and fortunately it worked for me, with no errors.
回答2:
You have to edit your tests Runner xml file.
See this example:
<test name="Employees Test">
<classes>
<class name="packagename.classname">
</class>
</classes>
</test>
In <class name="packagename.classname">
row you must enter your tests package name then name of class that you want to run.
Thanks and wish you all the best.
回答3:
I faced the similar issue on importing maven with testng project. This was solved by converting again into TestNg project by
right click on eclipse project > TestNG > Convert to TestNG
and replacing the existing testng.xml
file with the newly created. Clean and update the maven project with mvn install
Note: take backup of your testng.xml
回答4:
Go to
Project>Build Path>Configure Build Path>Libraries>Remove Error libraries
After Refresh project and run again program.
回答5:
Project>>Clean and Maven>>Update Project worked for me
回答6:
My 2 cents on the problem: I was experiencing the same problem, while some part of my path was in Cyrillic. So check the path to your project for special characters. Once I removed this, the problem was fixed
回答7:
I also ran into the same problem with TestNG version 6.14.2
However, this was due to a foolish mistake on my end and there is no issue whatsoever with maven, testng or eclipse. What I was doing was -
- Run project as "mvn clean"
- Select "testng.xml" file and right click on it to run as TestNG suite
- This was giving me the same error as reported in the original question
- I soon realized that I have not compiled the project and the required class files have not been generated that the TestNG would utilize subsequently
- The "target" folder will be generated only after the project is compiled (Run as "mvn build")
- If your project is compiled, this issue should not be there.
回答8:
I had the same issue when i was using selenium 3.11.xx dependency however my problem was resolved when i used selenium 3.4.x dependency.
回答9:
I had similar issue and the project had some build errors.
I did sudo -R 777 to the project and then I cleaned my project.
After that it worked fine.
Hope it helps.
回答10:
I had the same error when tried to run my tests in a JSF project.
I´m using Eclipse IDE (kepler). So, I did "project > clean" and then ran the tests again of the same project.
It worked!
回答11:
Note: You have to specify class name along with packages as given below.
<suite name="testNGLearning">
<test name="simpleTest">
<classes>
<class name="testngTests.TestNGSimpleTest" />
<class name="testngTests.TestMessageUtil" />
</classes>
</test>
</suite>
回答12:
Got the IDE working again. The solution is quite funny - and even a re-install, and deleting the IDE does not fix it on windows. What you need to do in that case, is to go to the testNG run configurations - and delete them all.
This is for the TestNG XML classpath error on windows OS. I am using spring tools suite 3.6.4.
Make certain that you delete all the configurations, make sure the project can build, and if there are no problems, the test should run now.
Regards
-Anthony Toorie
回答13:
In testng.xml file, remove "." from tag "" class name if you are not using packages.
回答14:
include the package name with class. It will remove your name. I also got the same issue but adding the package name with class fixed this issue.
回答15:
For me the problem was very strange.
I have a testng.xml file at the root of my Eclipse project. When I changed the file through Eclipse, it wasn't changing the testng.xml file in my directory.
Turns out it made a copy of the folder into the eclipse workspace..
Hope this helps someone out
回答16:
In my opinion if src has test/java/ folders then in build path out location should be like target/test-classes.
If src has main/java/ folders then in build path out location should be like target/classes.
回答17:
I came across the same issue stated above today. **setting the class-path again in eclipse ** solved the issue .
回答18:
I had no problems with this until recently.
Now I had to move the suite's xml test file into the root of the project I was testing.
It may be that there is a setting to point at the classes I am testing, but I have not found it.
回答19:
For me, the issue was because I excluded the test from compilation in the POM. My pom.xml looked like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<testExcludes>
<exclude>com/mycompany/app/AppTest.java</exclude>
</testExcludes>
</configuration>
</plugin>
After removing the <exclude>
, I was able to run the tests in AppTest.java
again.
回答20:
In my case I imported maven project as Default existing project in eclipse.After that I imported as maven project.That worked for me.
回答21:
This issue can be resolved by adding TestNG.class package to OnlineStore package as below
- Step 1: Build Path > Configure Build Path > Java Build Path > Select
"Project" tab
- Step 2: Click "add" button and select the project with contains the
TestNG source.
- Step 3 select TestNG.xml run as "TestNG Suite"
回答22:
I had this same problem when I imported my project from one PC to another on IntelliJ IDEA.
Below Solution worked for me:
- Import project using Git.
- After Importing IDE would prompt you a dialog on the bottom right corner saying "Import as Gradle", you need to select that but make Sure you have set JAVA_HOME and GRADLE(Gradle Home or Gradle wrapper both should work) properly.
- Run the build.gradle and make sure all the dependencies are downloaded correctly without any error.
- Now move to your Test Case and try to run with TestNG or JUnit and if you have followed above 3 steps properly you should able to run the test case.
回答23:
After done trying everything that I found on this issue, in eclipse,
I selected my project --> right click --> Run as --> Maven generate-sources
Then I re-ran my TestNG project and it ran perfectly fine without any issues.Hope that helps :)
回答24:
For me it was that I added Skip Tests checkbox/flag in the Maven Build of the Project
Therefore the test classes weren't compiled and then weren't found by TestNG
回答25:
I also had this issue.
I'm using IntelliJ IDEA.
I was using src/main/java
for configuration files and src/test/java
for test files.
Because of this testNG couldn't find the class path.
To prevent getting that error need to move all the files from src/main/java
to src/test/java
or vice versa.