Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
263 views
by The go-to Tester (218 points)
edited by

I have written a simple maven project and placed a Testng file in it . The testNG code is

package dataCollection;

import org.testng.annotations.Test;

public class Hello {
    @Test
    public void hello(){
        System.out.println("hello world");
    }

}

My project structure is as shown below

When i run it by mvn test the build is success but i cannot see console output. I get the following output-:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building dataCollection 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dataCollection ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ dataCollection ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to E:\Sandeep\EclipseWorkspace\dataCollection\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dataCollection ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ dataCollection ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dataCollection ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.769 s
[INFO] Finished at: 2017-03-12T18:57:06+05:30
[INFO] Final Memory: 11M/28M
[INFO] ------------------------------------------------------------------------
 

1 Answer

1 like 0 dislike
by
selected by
 
Best answer

It looks like, you are running your code using POM.xml file.

If so, you will need to map pom file to use TestNG.xml file using maven-surefire-plugin.

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>

 

Sample testng.xml file.

 

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="HW Tests">
  <test name="test1" >
    <classes>
      <class name="dataCollection.Hello" />
    </classes>
  </test>
</suite>

 

...