Error: org.testng.TestNGException: Cannot find class in classpath: EmpClass

前端 未结 30 1089
礼貌的吻别
礼貌的吻别 2020-12-09 08:17

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 impo

相关标签:
30条回答
  • 2020-12-09 08:52

    Make sure that your class is under src.

    0 讨论(0)
  • 2020-12-09 08:56

    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

    0 讨论(0)
  • 2020-12-09 08:58

    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.

    0 讨论(0)
  • 2020-12-09 08:58

    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 -

    1. Run project as "mvn clean"
    2. Select "testng.xml" file and right click on it to run as TestNG suite
    3. This was giving me the same error as reported in the original question
    4. 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
    5. The "target" folder will be generated only after the project is compiled (Run as "mvn build")
    6. If your project is compiled, this issue should not be there.
    0 讨论(0)
  • I had the same error. I cleaned the maven project then the problem was solved.

    0 讨论(0)
  • 2020-12-09 09:02

    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.

    0 讨论(0)
提交回复
热议问题