亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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[]>

正在回答

2 回答

這里用的的是Collection,在導入時,要使用? import java.util.Collection

Collection是接口,是Java集合框架的頂級接口;而Collections是一個具體的工具類,不是泛型類;Arrays.asList(...)返回的是個接口,使用了泛型,如下圖:

http://img1.sycdn.imooc.com//5a8e879e000139b505700114.jpg


另外,檢查?Calculate類是否存在,以及類的包路徑、測試類的路徑。

0 回復 有任何疑惑可以回復我~
#1

慕粉1406301482 提問者

非常感謝!
2018-02-23 回復 有任何疑惑可以回復我~

......系統反應慢半拍啊。。。。而且,我的錯誤也是真多

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

Junit參數化設置報錯

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號