How to use Interface IInstanceInfo class of org.testng package

Best Testng code snippet using org.testng.Interface IInstanceInfo

Run Testng automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package test.factory;
2
3import org.testng.Assert;
4import org.testng.IInstanceInfo;
5
6
7public class IInstanceFactory {
8  private static boolean m_invoked= false;
9  /**
10   * @testng.factory
11   */
12  public Object[] createObjects() {
13    return new IInstanceInfo[] {
14      new MyInstanceInfo(TestInterface.class, new TestInterfaceImpl())
15    };
16  }
17  
18  /**
19   * @testng.configuration afterTest="true"
20   */
21  public void afterVerification() {
22    Assert.assertTrue(m_invoked, "implementation of TestInterface test method should have been invoked");
23  }
24  
25  public static class MyInstanceInfo implements IInstanceInfo {
26    private Class m_clazz;
27    private Object m_instance;
28    
29    public MyInstanceInfo(Class clazz, Object instance) {
30      m_clazz= clazz;
31      m_instance= instance;
32    }
33
34    public Object getInstance() {
35      return m_instance;
36    }
37
38    public Class getInstanceClass() {
39      return m_clazz;
40    }
41  }
42  
43  public static interface TestInterface {
44    /**
45     * @testng.test
46     */
47    void testMethod();
48  }
49  
50  public static class TestInterfaceImpl implements TestInterface {
51
52    public void testMethod() {
53      m_invoked= true;
54    }
55    
56  }
57}
58
Full Screen
copy
1package org.testng;
2
3/**
4 * This class defines a pair of instance/class.  A method with @Factory
5 * can return an array of these objects instead of Object[] so that
6 * instances can be dynamic proxies or mock objects and still provide
7 * enough information to TestNG to figure out what classes the
8 * annotations should be looked up in.
9 *
10 * @author <a href="mailto:cedric@beust.com">Cedric Beust</a>
11 */
12public interface IInstanceInfo {
13
14  /**
15   * @return The instance on which the tests will be invoked.
16   */
17  public Object getInstance();
18
19  /**
20   * @return The class on which the TestNG annotations should be looked for.
21   */
22  public Class getInstanceClass();
23}
24
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on Interface-IInstanceInfo

    No relevant questions found for this class 😞

Most used methods in Interface-IInstanceInfo

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)