1

I tried cleaning my project through maven->clean and project->clean but it didnot work. I tried changing my output folders explicitly under build path but not sure what to select for src/test/java

I also updated my testng plugin in pom.xml

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd" >
  <modelVersion>4.0.0</modelVersion>
  <groupId>abc</groupId>
  <artifactId>xyz</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <description>Test</description>
  <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.11</version>
            <scope>compile</scope>
        </dependency>
    
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>21.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>3.3.1</version>
        </dependency>
        
        
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>
    
    <dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-chrome-driver</artifactId>
         <version>3.3.1</version>
    </dependency>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-ie-driver -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-ie-driver</artifactId>
        <version>3.3.1</version>
    </dependency>
        
        <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.16</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.16</version>
    </dependency>
        
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>
    
        
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.37</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
            <!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
        <dependency>
             <groupId>com.relevantcodes</groupId>
             <artifactId>extentreports</artifactId>
            <version>2.41.0</version>
        </dependency>
    
        
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>3.1.0</version>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
    
    </dependencies>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
 
  <build>

   <resources>
     <resource>
       <directory>src/test/resources</directory>
       <filtering>false</filtering>
       <includes>
          <include>**/*.properties</include>
          
        </includes>
     </resource>
   </resources>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>

                <source>1.8</source>
                <target>1.8</target>
             
            </configuration>
        </plugin>
    </plugins>

  </build>
</project>

Output folders for src/test/java and src/test/resources is /target/classes

and I am getting TestNG class not found in classpath error :

org.testng.TestNGException: 
Cannot find class in classpath: testclass file

Earlier this code was working fine. I just tried refractoring the project by changing artifact id of maven project and from then not able to proceed.

2
  • Set testng dependency to scope test instead of compile Commented Nov 30, 2017 at 16:20
  • Have you tried running Maven from the command line, or only from Eclipse? Commented Nov 30, 2017 at 19:56

5 Answers 5

2

Not sure how widely this applies, but I had success with this:

Right click > Java build path > Source Make sure Include:(All) and Exclude:(None) is checked for all 4 folders

src/main/java

src/main/resources

src/test/java

src/test/resources

Sign up to request clarification or add additional context in comments.

Comments

1

You need to add maven surefire plugin to run testNG classes. It's a miracle if you were able to run the tests earlier without this plugin. You have to add below plugin in the build phase to get going.

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.20.1</version>
    <configuration>
      <includes>
        <include>Sample.java</include>
      </includes>
    </configuration>
  </plugin>

If you don't want to include the tests manually then by default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:

"**/Test*.java"

"**/*Test.java"

"**/*Tests.java"

"**/*TestCase.java"

Comments

0

I think you have to convert non-maven project to maven project

right click on project->Configure->Convert it to Maven

3 Comments

This is maven project.
Try this, Just do Eclipse> Project > Clean and then run the test cases again. It should work. What it does in background is, that it will call mvn eclipse:clean in your project directory which will delete your .project and .classpath files and you can also do a mvn eclipse:eclipse - this regenerates your .project and .classpath files. Thus adding the desired class in the classpath.
tried. not working for me. i am not even seeing my compiled test classes in target folder
0

The issue for me was that the "Skip Tests" checkbox was checked.

RClick project -> Run As -> Run Configurations -> Maven Build (select your build configuration) -> Uncheck Skip Tests checkbox

This checkbox prevents Maven from compiling tests

If you want to compile the tests, but don't want to execute them during build process, add -DskipTests in Goals

Comments

0

Can you please try using the following maven command. The following maven command will compile the classes inside src/test folder.

mvn test-compile

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.