RetryAnalyzerCount with dataproviders

1,464 views
Skip to first unread message

testnguser

unread,
Jul 18, 2012, 5:24:17 PM7/18/12
to testng...@googlegroups.com
Hello,

I have a RetryTest class which extends RetryAnalyzerCount. It works perfectly for tests that have one test case in the dataprovider. If there are two test cases and both fails, it reruns the test only for the first testcase. If it passes for this rerun, it goes to the next test and does not rerun with the second test case in the same data provider.

Is this the usual behavior?

Thanks!

吴亭

unread,
Jul 19, 2012, 9:29:19 AM7/19/12
to testng...@googlegroups.com
After investigate the source code, currently, if you use the retry and dataprovider, retry method will only use the fist parameters to do the retry.

For example, due to this method will always return to the false, the first method {1,false} will use three times retry.

When the second method {0, true} failed, there is no counter to execute retry method.

  public RetryAnalyzerTest() {
    setCount(3);
  }

  @DataProvider(name="dataProvider")
  private Object[][] dataProvider() {
    return new Object[][] { { 1, false }, { 0, true } };
  }

   @Test(retryAnalyzer=RetryAnalyzerTest.class, dataProvider="dataProvider")
  public void testAnnotationWithDataProvider(int paf, boolean test) {
      System.out.println(paf + " "+test);
      System.out.println("-----------------------");
      System.out.println("Test method was called");
      Assert.assertTrue(false);
  }

2012/7/19 testnguser <techie...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/dB1gbwmYxSIJ.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

tech hari

unread,
Jul 19, 2012, 1:07:41 PM7/19/12
to testng...@googlegroups.com
Exactly, is there any other way(other than testng-failed.xml) to retry a failed method? Thanks!

Kevin Simonson

unread,
Jul 19, 2012, 2:12:37 PM7/19/12
to testng...@googlegroups.com

When I create the following code in IntelliJ:,

 

---Abc.java---------------------------------------------------------------------

 

package org.familysearch.links.uitests;

 

import org.testng.annotations.*;

 

@Test(enabled = false, groups = "xyz")

public class Abc {

 

  @BeforeClass(alwaysRun = true)

  private void def () {

 

    System.out.println( "Beginning of {def()}.");

    String user      = "me"

    String password  = "em";

    String sessionId = pqr( user, password);

    System.out.println( "End of {def()}.");

  }

 

  public void ghi () {

    System.out.println( "In {ghi()}.");

  }

 

  public void jkl () {

    System.out.println( "In {jkl()}.");

  }

 

  public void mno () {

    System.out.println( "In {mno()}.");

  }

 

  public String pqr ( String username

                    , String password) {

    System.out.println( "In {pqr()}.");

    return "Success!";

  }

}

--------------------------------------------------------------------------------

 

and right click outside of any method and click on <Run 'Abc'>, I get the following output:

 

--------------------------------------------------------------------------------

Beginning of {def()}.

In {pqr()}.

End of {def()}.

In {ghi()}.

In {jkl()}.

In {mno()}.

--------------------------------------------------------------------------------

 

So TestNG knows somehow that {ghi()}, {jkl()}, and {mno()} are test methods, and should be run independently of any other methods, and it knows somehow that {pqr()} is not a test method, and should only be run when it's called by {def()}.  My question is, how does TestNG tell that {pqr()} is not a test method like the other three test methods?  It's inside class {Abc}, and {Abc} has the {@Test} annotation right before it; why aren't all methods inside {Abc} test methods?  Is it the fact that {pqr()} has parameters and doesn't have a data provider that distinguishes it from the other test methods?

 

Kevin S

 



NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.


Cédric Beust ♔

unread,
Jul 19, 2012, 2:34:22 PM7/19/12
to testng...@googlegroups.com
Hi Kevin,

You figured it out: the fact that this method takes parameters and doesn't have a data provider or a @Parameter annotation tells TestNG it's not a test method (and besides, TestNG wouldn't know how to call it since it doesn't know what parameters to pass).

-- 
Cédric




吴亭

unread,
Jul 19, 2012, 9:58:59 PM7/19/12
to testng...@googlegroups.com
Hi,

If you could try the latest version of testng (TestNG 6.8 -snapshot version)

You can orverride retry method in your test case like this, (3 is a retry number, you can update it according to your test cases.)

    @Override
    public boolean retry(ITestResult result) {
        boolean retry = false;
        int count = getCount();
        if (count > 0) {
            retry = retryMethod(result);
        }
        setCount(--count);

        if (getCount()==-1){
            setCount(3);
        }
        return retry;
    }

2012/7/20 tech hari <techie...@gmail.com>
Reply all
Reply to author
Forward
0 new messages