Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Junit multi-group test data test

Shulou Source: shulou.com Published: 2022-06-03 02:54:25 09月28日 Update

Use Junit to specify multiple sets of test data for testing.

SHA3Utils code repository used by the test method address: java-core

Parameterized test

Specify multiple parameters to be tested in batches and test them one by one according to the data

Import org.junit.Test;import org.junit.runner.RunWith;import org.junit.runners.Parameterized;import java.util.Arrays;import java.util.List;/** * Description: JunitTest specifies multiple parameters to be tested in batches, and tests them one by one according to the data *

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-256output:% 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)) }} Theories Test

Provide the permutation and combination values of a set of parameters as the input parameters of the method to be tested, and test them one by one according to the method.

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 provides the permutation and combination values of a set of parameters as the input parameters of the method to be tested, and tests them one by one according to the method *

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);}}

Tags: Tests parameters methods data multiple combinations inputs warehouses code addresses Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Huawei Shulou Information Linux MySQL