
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
TestNG Error: Cannot Find Class in Classpath
User may encounter Cannot find class in classpath exception while executing tests in TestNG framework. The meaning of this error is TestNG unable to find the class as mentioned in testng.xml. This can be caused because of the following reasons ?
In the TestNG XML, the class tag having the name attribute. User should define the class name as <package_name>.<class_name> format. It should not have the .java extension.
In the TestNG XML, the class file is incorrect and hence unable to determine the classpath of the class.
Errors within the project are present and may require a clean project.
In the TestNG XML, the class file name is incorrect.
Sometimes, user doesn't have any exception or wrong name, yet gets the classpath not found exception.
In this article, we will see what checklists and way are to resolve the error.
Approach/Algorithm to Solve this Problem
Step 1: Make sure class name is provided in proper format and name is correctly typed in testng.xml. If class is inside the package write the class name as <package>.
Step 2: Make sure class name is not ending with .java extension in testng.xml.
Step 3: If above 2 checks are reviewed and issue yet persists, clean the project by navigating as Project ?> Clean (in eclipse) while file ?>Invalidate cache/restart (in Intellij) or you can do Build ?> Rebuild project
Step 4: If issue still persists and project is using maven, try to do update maven project.
Step 4: If none of above solution works, Navigate to build path as right click on project? > properties ?> java build path. Now check library files. if you see any error then resolve it by adding missing file at given location.