Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A @BeforeClass failure skips all remaining tests in sibling instances generated by an @Factory. #71

Closed
lsjuanny opened this issue Jul 20, 2011 · 2 comments

Comments

@lsjuanny
Copy link

Such as, in a Factory, will generate three classes with two test methods. The first class passed, and the second one failed, then the third class will skipped. Test result look like:
Test 1.1 pass
Test 1.2 pass
beforeClass 2 fail
Test 2.1 skip
Test 2.2 skip
beforeClass 3 skip
Test 3.1 skip
Test 3.2 skip

Please see the attachment source code to repro this issue.

@lsjuanny
Copy link
Author

Please use following code:

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import static org.testng.Assert.fail;

@test(suiteName = "com.juan.test", testName = "Factory Test")
public class FactoryTest {
/**
* Generate 3 test in this factory
*
* @return
*/
@factory
public static Object[] createInstances() {
return new Object[] { new FactoryTest(1), new FactoryTest(2),
new FactoryTest(3) };
}

private final int instanceIndex;

public FactoryTest(int instanceIndex) {
    this.instanceIndex = instanceIndex;
}

@BeforeTest()
public void before() throws InterruptedException {
    System.out.println("Before Test " + this.instanceIndex);
}

@BeforeClass(timeOut = 1000)
public void beforeClass() throws InterruptedException {
    System.out.println("Before Class " + this.instanceIndex);

    if (this.instanceIndex >= 2) {
        fail("Before class failed.");
    }
}

@Test(description = "Doing the test 1.", timeOut = 1000)
public void timeOutTest1() throws InterruptedException {
    System.out.println(String.format("Test %s.%s", this.instanceIndex, 1));
}

@Test(description = "Doing the test 2.", timeOut = 1000)
public void timeOutTest2() throws InterruptedException {
    System.out.println(String.format("Test %s.%s", this.instanceIndex, 2));
}

@AfterClass(timeOut = 1000, alwaysRun = true)
public void afterClass() throws InterruptedException {
    System.out.println("After class " + this.instanceIndex);
}

@AfterTest(alwaysRun = true)
public void after() throws InterruptedException {
    System.out.println("After Test " + this.instanceIndex);
}

}

@lsjuanny lsjuanny reopened this Jul 20, 2011
@cbeust
Copy link
Collaborator

cbeust commented Aug 3, 2011

Use: <suite configfailurepolicy="continue">

@cbeust cbeust closed this as completed Aug 3, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants