对JUNIT4使用多个@parameters [英] Using multiple @parameters for JUNIT4
本文介绍了对JUNIT4使用多个@parameters的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在JUNIT4中编写参数化测试,但是我不知道如何制作多个参数,例如:
I am trying to write parameterize test in JUNIT4 and I don't know how to make multiple parameters for instance :
@ parameter1 {1,2,3,4}
@parameter1 {1,2,3,4}
@ test1 使用@ parameter1
@test1 run test using @parameter1
@ parameter2 {3,55,66,77}
@parameter2 {3,55,66,77}
@ test2 使用@ parameters2
@test2 run test using @parameters2
任何人都可以向我提供示例代码片段,不胜感激.
Could anyone provide me with a sample snippet, that would be greatly appreciated.
谢谢.
推荐答案
看起来您可以利用 @ TestedOn .
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.experimental.theories.suppliers.TestedOn;
import org.junit.runner.RunWith;
@RunWith(Theories.class)
public class SuppliedByTest {
@Theory
public void test1(@TestedOn(ints = { 2, 3, 4, 7, 13, 23, 42 }) int i) {
System.out.println(i);
}
@Theory
public void test2(@TestedOn(ints = { 6, 3, 4, 7, 13, 23, 42 }) int i) {
System.out.println(i);
}
}
这篇关于对JUNIT4使用多个@parameters的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文