使用不同的数据多次运行相同的 JUnit 测试用例
有没有办法告诉JUnit在进入下一个测试用例之前,使用不同的数据连续多次运行特定的测试用例?
有没有办法告诉JUnit在进入下一个测试用例之前,使用不同的数据连续多次运行特定的测试用例?
看看 junit 4.4 理论:
import org.junit.Test;
import org.junit.experimental.theories.*;
import org.junit.runner.RunWith;
@RunWith(Theories.class)
public class PrimeTest {
@Theory
public void isPrime(int candidate) {
// called with candidate=1, candidate=2, etc etc
}
public static @DataPoints int[] candidates = {1, 2, 3, 4, 5};
}
这听起来像是参数化测试的完美候选者。
但是,基本上,参数化测试允许您对不同的数据运行同一组测试。
以下是一些关于它的好博客文章: