0

What am I doing wrong??? I have no idea why the parameters aren't passed!!! Am trying to pass the values from an external excel sheet... Please help!!

And guys please don't mark this as duplicate!! Thanks in advance

P.S I am trying not to use maven..

import Data.Bean;
import org.easetech.easytest.annotation.DataLoader;
import org.easetech.easytest.annotation.Param;
import org.easetech.easytest.loader.LoaderType;
import org.easetech.easytest.runner.DataDrivenTestRunner;
import org.junit.runner.RunWith;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

/**
 *
 * @author Effitrac
 */
public class TestNGTestCases {

    public TestNGTestCases() {
    }
    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    // @Test
    // public void hello() {}

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @BeforeMethod
    public void setUpMethod() throws Exception {
    }

    @AfterMethod
    public void tearDownMethod() throws Exception {
    }

    /**
     *
     */
    @RunWith(DataDrivenTestRunner.class)
    @DataLoader(filePaths = {"d:/data/kishore/testdata.csv"}, loaderType = LoaderType.CSV)
    public class TestExcelDataLoader {

            Bean b = new Bean();
        @Test
        public void testwelcome(@Param(name = "name") String name, @Param(name = "custID") Integer custID) {
            System.out.print("Executing getExcelTestData :");
//            System.out.println("Name : " + name + " ID : " + custID);
            b.setName(name);
            b.setCustID(custID);
            b.doit();
            System.out.println("Name : " + b.getName() + " ID : " + b.getCustID() + " Result : " + b.getResult());
//            System.out.println("Name : " + name + " ID : " + custID + " Result : " + b.getResult());

        }
    }
}

This is the Output I receive....

[TestNG] Running:
  Command line suite

[VerboseTestNG] RUNNING: Suite: "Command line test" containing "1" Tests (config: null)
[VerboseTestNG] SKIPPED: "Command line test" - TestNGTestCases$TestExcelDataLoader.testwelcome(java.lang.String, java.lang.Integer) finished in 16 ms
[VerboseTestNG] org.testng.TestNGException: 
[VerboseTestNG] Method testwelcome requires 2 parameters but 0 were supplied in the @Test annotation.
[VerboseTestNG] 
[VerboseTestNG] ===============================================
[VerboseTestNG]     Command line test
[VerboseTestNG]     Tests run: 1, Failures: 0, Skips: 1
[VerboseTestNG] ===============================================

===============================================
Command line suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

Java Result: 2
Deleting directory C:\Users\Effitrac\AppData\Local\Temp\TestNGTestCases
test:
BUILD SUCCESSFUL (total time: 6 seconds)

1 Answers1

0

Not sure why do you need to use third party library to run TestNG with DataDrivenTestRunner.class. Below works well for all the cases without any issues. Also why did you create TestNGTestCases class as neither you are extending it nor adding any tests to it.

package practise;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;

public class SO34677983 {
    @Test(dataProvider = "dp")
    public void f(Integer CustId, String Name) {
        System.out.println("Verifying something here");
    }

    @DataProvider
    public Object[][] dp() throws IOException {
        File csvRead = new File("someFilePath.csv");
        BufferedReader br = new BufferedReader(new FileReader(csvRead));
        String line = "";
        Object[][] data = new Object[2][2];
        int dataNum = 0;
        while ((line = br.readLine()) != null) {
            data[dataNum][0] = line.split(",")[0];
            data[dataNum][1] = line.split(",")[1];
            dataNum++;
        }
        br.close();
        return data;
    }
}
Mrunal Gosar
  • 4,595
  • 13
  • 48
  • 71
  • can you give me a link for a complete program example? And also please give me a sample format how the excel sheet should be.. – Kishore Jagadeesan Jan 09 '16 at 04:27
  • excel sheet format depends on your requirement. like first row can be column headers then further rows can be your test data (Also consider keeping test data in CSV or database).. with regards to the complete programme..above is complete programme snippet..u can replace units of program. – Mrunal Gosar Jan 09 '16 at 07:12
  • Thank you for your help!!!. Now i want to write the test result in a excel sheet.... Can you help me with that? – Kishore Jagadeesan Jan 11 '16 at 06:33
  • Can you first try that at your end based on the tutorials available on the internet and then if you are stuck anywhere then come back to Stackoverflow – Mrunal Gosar Jan 11 '16 at 09:39