Junit5 创建数据 dataProvider

Gradle

build.gradle 添加

test {
	useJUnitPlatform()
}

dependencies {
	// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
	testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.0'

	// https://mvnrepository.com/artifact/junit/junit
	testCompile group: 'junit', name: 'junit', version: '4.13.1'
}

代码

package com.dytest.shared.maskword;

import com.dy.shared.module.maskword.MaskWordHelper;
import com.dy.shared.module.maskword.MaskWordType;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.runner.RunWith;

@RunWith(DataProviderRunner.class)
public class MaskWordTest {

    @DataProvider
    public static Object[][] dataProviderForMaskWordConfig(){
        return new Object[][]{
                {MaskWordType.PATTERN.getType(), "****敏感词...审核**", "敏感词", "*"},
                {MaskWordType.WORD.getType(), "草莓|花生", "不想吃草莓,爱花生abc", "不想吃**,爱**abc"},
        };
    }

    @Test
    @UseDataProvider("dataProviderForMaskWordConfig")
    public void testMaskWord(int maskWordType, String pattern, String sourceText, String expectReplaceText){
        MaskWordHelper.addMaskWordConfig(MaskWordType.getMaskWordType(maskWordType), pattern);
        Assertions.assertTrue(MaskWordHelper.isContainMaskWord(sourceText));

        String replaceText = MaskWordHelper.replace(sourceText);
        Assertions.assertEquals(expectReplaceText, replaceText);
    }
}
  1. @Test 标签 是 org.junit.Test 包里面的
  2. @UseDataProvider

下载手册

Junit5

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值