Junit參數化設置報錯
package com.imooc.junit;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collections;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ParameterTest {
?? ?int expection = 0;
?? ?int input01 = 0;
?? ?int input02 = 0;
?? ?
?? ?@Parameters
?? ?public static Collections<Object[]> t() {
?? ??? ?return Arrays.asList(new Object[][]{
?? ??? ??? ??? ?{3,1,2},
?? ??? ??? ??? ?{4,2,2}
?? ??? ?}) ;
?? ?}
?? ?
?? ?public ParameterTest(int expenction,int input01,int input02){
?? ??? ?this.expection = expenction;
?? ??? ?this.input01 = input01;
?? ??? ?this.input02 = input02;
?? ?}
?? ?
?? ?public void testAdd(){
?? ??? ?assertEquals(expection, new Calculate().add(input01, input02));
?? ?}
}
同樣的代碼,Collection不加上s反而報錯更多,小新人不了解,是不是有什么版本問題?(我一模一樣的敲,試過把老師的代碼復制過來,也是報錯)
說是類型無法轉換。。。?
The type Collections is not generic; it cannot be parameterized with arguments <Object[]>
2018-02-22
這里用的的是Collection,在導入時,要使用? import java.util.Collection
Collection是接口,是Java集合框架的頂級接口;而Collections是一個具體的工具類,不是泛型類;Arrays.asList(...)返回的是個接口,使用了泛型,如下圖:
另外,檢查?Calculate類是否存在,以及類的包路徑、測試類的路徑。
2017-06-27
......系統反應慢半拍啊。。。。而且,我的錯誤也是真多