无法执行Junit参数化测试执行

时间:2016-03-09 21:24:40

标签: java junit

问题运行这一小段代码时出现以下错误。我正在尝试学习Selenium和Junit自动化,因此出现了问题。请帮忙。

  

错误 java.lang.Exception:类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);
    }
}

1 个答案:

答案 0 :(得分:1)

您导入了错误的Parameters课程。请使用

import org.junit.runners.Parameterized.Parameters;
相关问题