1、junit 参数测试四个步骤
a、对测试类添加注解 @RunWith(Parameterized.class)

b、将需要使用变化范围参数值测试的参数定义为私有变量

c、 使用上一步骤声明的私有变量作为入参,创建构造函数

d、创建一个使用@Parameters 注解的公共静态方法,它将需要测试的各种变量值通过集合的形式返回。

e、使用定义的私有变量定义测试方法

2、@RunWith(Parameterized.class)和@RunWith(SpringRunner.class)二选一
使用参数化测试要用@RunWith(Parameterized.class),而springboot测试要用RunWith(SpringRunner.class),且
RunWith只能选一个,所以百度一番找到一个讲解怎么实现的的博客。
@RunWith(Parameterized.class)和@RunWith(SpringJUnit4ClassRunner.class) - CSDN博客
按照博客中指出的方式手动启动一个spring容器 但是还是报下列错误
You can possibly workaround the problem by overriding the org.junit.runners.ParentRunner#filter by extending the Parameterized
最后在stackoverflow找到解决办法java - initializationError with Eclipse and JUNIT4 when executing a single test - Stack Overflow
扩展Parameterized类后测试类正常运行。
网友评论