1.哪个测试框架最适合这里?
答:类参数化
2.参数化Junit合适吗?
答:是的,你是对的
3.请提供一些指导方针,以便使用推荐的框架。
Ans: 用于断言实际和预期的结果。
假设您想通过 char 检查文件 char 的内容,您可以使用FileUtils.contentEquals(file1, file2)
commons apache io
让我们看看这个例子:
public class Calc{
public static int add(int a, int b) {
return a + b;
}
}
朱尼特
@RunWith(value = Parameterized.class)
public class ParameterizedTest {
private int numberA;
private int numberB;
private int expected;
// Inject via constructor
// for {8, 2, 10}, numberA = 8, numberB = 2, expected = 10
public ParameterizedTest(int numberA, int numberB, int expected) {
this.numberA = numberA;
this.numberB = numberB;
this.expected = expected;
}
// name attribute is optional, provide an unique name for test
// multiple parameters, uses Collection<Object[]>
@Parameters(name = "{index}: testAdd({0}+{1}) = {2}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{1, 1, 2},
{2, 2, 4},
{8, 2, 10},
{4, 5, 9},
{5, 5, 10}
});
}
@Test
public void test_addTwoNumbes() {
assertThat(Calc.add(numberA, numberB), is(expected));
}
}
参考