H1b1
H1b1

Reputation: 51

Unable to perform Junit Parameterized test execution

Issue Getting the following error when running this small bit of code. I am attempting to learn Selenium and Junit automation, hence having teething problems. Please help.

Error java.lang.Exception: No public static parameters method on class jUnit.ParameterizedTest.

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.testng.annotations.Parameters;

import java.util.*;

// Step 1
@RunWith(Parameterized.class)
public class ParameterizedTest {

    // Step 2, declare global parameters.
    String username;
    String password;
    int zipcode;

    // Step 3, make a constructor of the class with same no. of parameters as the
    // the number of global parameters declared.

    public ParameterizedTest(String username, String password, int zipcode) {
        this.username = username;
        this.password = password;
        this.zipcode = zipcode;
    }

    // Step 4, get all paramter values to be tested in an Arrays.asList format.

    @Parameters
    public static Collection<Object[]> getData() {
        Object data[][] = new Object[3][3];

        data[0][0] = "U1";
        data[0][1] = "P1";
        data[0][2] = "Z1";

        data[1][0] = "U1";
        data[1][1] = "P1";
        data[1][2] = "Z1";

        data[2][0] = "U1";
        data[2][1] = "P1";
        data[2][2] = "Z1";

        return Arrays.asList(data);
    }

    @Test
    public void loginTest() {
        System.out.println(username + "   " + password + "   " + zipcode);
    }
}

Upvotes: 0

Views: 1193

Answers (1)

Stefan Birkner
Stefan Birkner

Reputation: 24560

You're importing the wrong Parameters class. Please use

import org.junit.runners.Parameterized.Parameters;

Upvotes: 7

Related Questions