Bug in preserve-order with factory

79 views
Skip to first unread message

Felipe Knorr Kuhn

unread,
Dec 23, 2010, 1:30:17 PM12/23/10
to testng...@googlegroups.com
Hello, Cédric

I'm experimenting with factories and found bug with preserve order:

public class WebTestFactory {
    @Factory
    public Object[] createInstances() {
        Object[] result = new Object[10];
        for (int i = 0; i < 10; i++) {
            result[i] = new WebTest(i * 10);
        }
        return result;
    }
}

public class WebTest {
  private int m_numberOfTimes;
  public WebTest(int numberOfTimes) {
    m_numberOfTimes = numberOfTimes;
  }
 
  @Test
  public void testServer() {
   for (int i = 0; i < m_numberOfTimes; i++) {
     // access the web page
    }
  }
}

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Factory" verbose="10">
    <listeners>
        <listener class-name="org.testng.reporters.EmailableReporter" />
    </listeners>

    <test name="Factory Test" preserve-order="true">
        <classes>
            <class name="WebTestFactory"/>
        </classes>
    </test>
</suite>

RemoteTestNG starting
java.lang.NullPointerException
    at org.testng.internal.MethodInstance$1.compare(MethodInstance.java:57)
    at org.testng.internal.MethodInstance$1.compare(MethodInstance.java:38)
    at java.util.Arrays.mergeSort(Arrays.java:1270)
    at java.util.Arrays.mergeSort(Arrays.java:1281)
    at java.util.Arrays.sort(Arrays.java:1210)
    at java.util.Collections.sort(Collections.java:159)
    at org.testng.PreserveOrderMethodInterceptor.intercept(PreserveOrderMethodInterceptor.java:28)
    at org.testng.TestRunner.createParallelWorkers(TestRunner.java:953)
    at org.testng.TestRunner.privateRun(TestRunner.java:734)
    at org.testng.TestRunner.run(TestRunner.java:600)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
    at org.testng.SuiteRunner.run(SuiteRunner.java:223)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:957)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:886)
    at org.testng.TestNG.run(TestNG.java:820)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:110)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)

Cédric Beust ♔

unread,
Dec 23, 2010, 2:43:52 PM12/23/10
to testng...@googlegroups.com
Hi Felipe,

You seem to be using an older version of TestNG, can you update to 5.14.6 and try again?

Thanks.

-- 
Cédric



--
You received this message because you are subscribed to the Google Groups "testng-users" group.
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.



--
Cédric


Felipe Knorr Kuhn

unread,
Dec 23, 2010, 3:02:41 PM12/23/10
to testng...@googlegroups.com
You were right. I was using an older Eclipse plugin and forgot to check "use the project's TestNG"

I got a problem with the emailable report now:

[EmailableReporter] [ERROR] output file
java.io.FileNotFoundException: /home/knorr/workspace/Temp/test-output/emailable-report.html (No such file or directory)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
    at java.io.FileWriter.<init>(FileWriter.java:73)
    at org.testng.reporters.EmailableReporter.createWriter(EmailableReporter.java:74)
    at org.testng.reporters.EmailableReporter.generateReport(EmailableReporter.java:58)
    at org.testng.TestNG.generateReports(TestNG.java:892)
    at org.testng.TestNG.run(TestNG.java:870)

    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:110)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)

Perhaps you could use mkdirs() to create the full path before creating the reports?

Thanks,

FK

2010/12/23 Cédric Beust ♔ <ced...@beust.com>

Cédric Beust ♔

unread,
Dec 23, 2010, 3:36:25 PM12/23/10
to testng...@googlegroups.com
TestNG could probably fail more gracefully, but if this directory doesn't exist, it means that there are no tests to report on...

-- 
Cédric

Felipe Knorr Kuhn

unread,
Dec 27, 2010, 9:41:59 AM12/27/10
to testng...@googlegroups.com
Not really.

What happened was that in the TestNG preferences, I set the output directory to "/test-output", unchecked the absolute path option and disabled the default listeners.

If I don't create the test-output dir, TestNG fails with that stacktrace.

If I create it before running the tests, there is no problem and the reports are generated.

It's just a matter of calling mkdirs() to create all the dirs before trying to dump the reports there.

Thanks,

FK

2010/12/23 Cédric Beust ♔ <ced...@beust.com>
fail more gracefully, but if this directory doesn't exist, it means that there are no tests to report on...

Cédric Beust ♔

unread,
Dec 27, 2010, 12:07:38 PM12/27/10
to testng...@googlegroups.com
FYI, I added a call mkdirs() a few days ago (it's in master, not sure this change made it in 5.14.6 but you're welcome to try).

-- 
Cédric


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
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.



--
Cédric


Reply all
Reply to author
Forward
0 new messages