TestNG: How to execute several test methods in order with data supplied from DataProvider -


is there way execute several test methods in order using different data data provider?

e.g.

@dataprovider(name = "test1") public object[][] createdata1() {     return new object[][] {         { "cedric", new integer(36) },         { "anne", new integer(37)},      }; }   @test(dataprovider = "test1") public void verifydata1(string n1, integer n2) {     system.out.println(n1 + " " + n2); }  @test public void verifydata2() {     system.out.println("verify2"); } 

and output of running be
cedric 36
verify2
anne 37
verify2

here 1 way it: use annotation specify method should receive data:

public class {    @dataprovider   public object[][] dp(method m) {     if (m.getannotation(different.class) != null) {       return new object[][] {           new object[] { "different-a", "different-b" },           new object[] { "different-c", "different-d" },         };       } else {         return new object[][] {             new object[] { "c", "d" },             new object[] { "a", "b" },         };       }     }    @test(dataprovider = "dp")   public void test1(string a, string b) {     system.out.println("test1: " + + " " + b);   }    @different   @test(dataprovider = "dp")   public void test2(string a, string b) {     system.out.println("test2: " + + " " + b);   } } 

the annotation:

@retention(java.lang.annotation.retentionpolicy.runtime) @target({method}) public @interface different {} 

the output:

test1: c d test1: b test2: different-a different-b test2: different-c different-d 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -