testng-team / testng-googlecode

DEPRECATED: Automatically exported from code.google.com/p/testng
0 stars 0 forks source link

@Factory tests result in incorrect test-failed.xml #21

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
1. Create Factory

import org.testng.annotations.Factory;
import org.testng.annotations.Parameters;

public class TestFactory {
    @Factory
    @Parameters( { "param1", "param2" })
    public Object[] createInstances(String param1, String param2) {
        final Object[] result = new Object[1];
        result[0] = new Tests(param1, param2);
        return result;
    }
}

2. Create Tests (some of them should fail)
3. Run testng
4. Get a testg-failed.xml with all failed tests
5. Rerun test with testng-failed.xml

What is the expected output? What do you see instead?

[Parser] Running:
  /home/svj/workspace/webtests/target/surefire-reports/testng-failed.xml

org.apache.maven.surefire.booter.SurefireExecutionException: 
Could not create an instance of class class
net.sprd.qa.webtests.checkout.CheckoutTests:
net.sprd.qa.webtests.checkout.CheckoutTests.<init>(java.lang.String).
Please make sure it has a constructor that accepts either a String or no
parameter.; nested exception is org.testng.TestNGException: 
Could not create an instance of class class
net.sprd.qa.webtests.checkout.CheckoutTests:
net.sprd.qa.webtests.checkout.CheckoutTests.<init>(java.lang.String).
Please make sure it has a constructor that accepts either a String or no
parameter.
org.testng.TestNGException: 
Could not create an instance of class class
net.sprd.qa.webtests.checkout.CheckoutTests:
net.sprd.qa.webtests.checkout.CheckoutTests.<init>(java.lang.String).
Please make sure it has a constructor that accepts either a String or no
parameter.
        at
org.testng.internal.ClassHelper.tryOtherConstructor(ClassHelper.java:407)
        at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:332)
        at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:62)
        at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:81)
        at
org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:102)
        at org.testng.TestRunner.initMethods(TestRunner.java:270)
        at org.testng.TestRunner.init(TestRunner.java:216)
        at org.testng.TestRunner.init(TestRunner.java:178)
        at org.testng.TestRunner.<init>(TestRunner.java:127)
        at
org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:4
54)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:235)
        at org.testng.SuiteRunner.run(SuiteRunner.java:191)
        at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:808)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:776)
        at org.testng.TestNG.run(TestNG.java:701)
        at
org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
        at
org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.j
ava:92)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBoote
r.java:334)
        at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:980)

Problem: Testng writes the wrong class in testng-failed.xml. Instead of the
factory class "TestFactory" it links the test class "Tests". This means,
every rerun with factory tests fail.

What version of the product are you using? On what operating system?

testng 5.7 / Java build 1.6.0-b105 / Ubuntu 7.04

Original issue reported on code.google.com by sven.j...@gmail.com on 8 Apr 2008 at 4:43

GoogleCodeExporter commented 9 years ago
This limitation makes @Factory unusable for large testing.

Also there's no way we can override the class annotation -> Issue 26

Original comment by biethb@gmail.com on 30 Jul 2008 at 2:48