使用 Junit
指定多組測試數(shù)據(jù)進行測試。
創(chuàng)新互聯(lián)公司長期為上千家客戶提供的網(wǎng)站建設服務,團隊從業(yè)經(jīng)驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為頭屯河企業(yè)提供專業(yè)的成都網(wǎng)站建設、網(wǎng)站建設,頭屯河網(wǎng)站改版等技術服務。擁有10年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
測試方法使用的 SHA3Utils
代碼倉庫地址: java-core
批量指定多個待測參數(shù), 按數(shù)據(jù)逐一測試
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.List;
/**
* Description: JunitTest 批量指定多個待測參數(shù), 按數(shù)據(jù)逐一測試
* Blog: http://blog.wxcsdb88.com
*
* @author wxcsdb88
* @since 2017-12-10 00:21
**/
@RunWith(Parameterized.class)
public class JunitTestParameterizeDemo {
private String input;
public JunitTestParameterizeDemo(String input) {
this.input = input;
}
@Parameterized.Parameters
public static List getParams() {
return Arrays.asList("hello", "hi", "good morning", "how are you");
}
@Test
public void sha224() throws Exception {
String result = SHA3Utils.sha224(input);
System.out.println(String.format("input is %s, SHA3-224 output: %s", input, result));
}
@Test
public void sha256() throws Exception {
String result = SHA3Utils.sha256(input);
System.out.println(String.format("input is %s, SHA3-256 output: %s", input, result));
}
@Test
public void sha384() throws Exception {
String result = SHA3Utils.sha384(input);
System.out.println(String.format("input is %s, SHA3-384 output: %s", input, result));
}
@Test
public void sha512() throws Exception {
String result = SHA3Utils.sha512(input);
System.out.println(String.format("input is %s, SHA3-512 output: %s", input, result));
}
}
提供一組參數(shù)的排列組合值作為待測試方法的輸入?yún)?shù), 按照方法逐一測試
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
/**
* Description: theories 提供一組參數(shù)的排列組合值作為待測試方法的輸入?yún)?shù), 按照方法逐一測試
* Blog: http://blog.wxcsdb88.com
*
* @author wxcsdb88
* @since 2017-12-10 00:21
**/
@RunWith(Theories.class)
public class JUnitTestDemoTheories {
@DataPoints
public static String[] inputs = {"hello", "hi", "good morning", "how are you"};
@Theory
public void sha224Theories(String input) throws Exception {
String result = SHA3Utils.sha224(input);
System.out.println(String.format("input is %s, SHA3-224 output: %s", input, result));
}
@Theory
public void sha256(String input) throws Exception {
String result = SHA3Utils.sha256(input);
System.out.println(String.format("input is %s, SHA3-256 output: %s", input, result));
}
@Theory
public void sha384(String input) throws Exception {
String result = SHA3Utils.sha384(input);
System.out.println(String.format("input is %s, SHA3-384 output: %s", input, result));
}
@Theory
public void sha512(String input) throws Exception {
String result = SHA3Utils.sha512(input);
System.out.println(String.format("input is %s, SHA3-512 output: %s", input, result));
}
}