Constructor based factory bug

62 views
Skip to first unread message

Stephen Colebourne

unread,
May 15, 2013, 8:06:03 AM5/15/13
to testng...@googlegroups.com
This test throws exceptions unrelated to the fact that the input to the factory constructor is an empty array:

FAILED CONFIGURATION: @BeforeClass setUpClass
java.lang.NullPointerException
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:178)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)




import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;

/**
 * Test.
 */
@Test
public class FailingFactoryTest {

  private final String _value1;
  private final String _value2;
  private String _setUp;

  @Factory(dataProvider = "input")
  public FailingFactoryTest(String value1, String value2) {
    _value1 = value1;
    _value2 = value2;
  }

  @DataProvider(name = "input")
  static Object[][] data_input() {
    return new Object[0][0];
  }

  @BeforeClass
  public void setUpClass() {
    _setUp = "Hello " + _value1 + _value2;
  }

  @BeforeMethod
  public void setUp() {
    _setUp = "Hello " + _value1 + _value2;
  }

  public void test() {
    assertEquals("Hello world", _setUp);
  }

}


It looks like the empty array is not checked and trapped in TestNG when using @Factory on constructors. TestNG then continues to try to initialise the class even though that is clearly impossible...

thanks
Stephen

Reply all
Reply to author
Forward
0 new messages