Using multiple @parameters for JUNIT4

不羁的心 提交于 2019-12-12 14:33:53

问题


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}

@test1 run test using @parameter1

@parameter2 {3,55,66,77}

@test2 run test using @parameters2

Could anyone provide me with a sample snippet, that would be greatly appreciated.

thank you.


回答1:


Looks like you could take advantage of the @Theories and @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);
  }
}


来源:https://stackoverflow.com/questions/7437705/using-multiple-parameters-for-junit4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!