开发者

Using multiple @parameters for JUNIT4

开发者 https://www.devze.com 2023-04-05 09:39 出处:网络
I am trying to write parameterize test in JUNIT4 and I don\'开发者_如何学Pythont know how to make multiple parameters for instance :

I am trying to write parameterize test in JUNIT4 and I don'开发者_如何学Pythont 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.


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);
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号