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

@BeforeMethod in super classes depends on method visibility #473

Open
matthauck opened this issue Dec 27, 2013 · 1 comment
Open

@BeforeMethod in super classes depends on method visibility #473

matthauck opened this issue Dec 27, 2013 · 1 comment

Comments

@matthauck
Copy link

See post on the user's group: https://groups.google.com/forum/#!topic/testng-users/fJd90c1RPWM

With a little bit of ad-hoc testing, it seems that if a superclass has a @BeforeMethod annotation, the sub-test-class only run it first (or even at all?) if it has protected visibility

import java.util.*;
import static org.testng.Assert.*;
import org.testng.annotations.*;

class SuperSampleTest {

    List<String> order = new ArrayList<>(2);

    @BeforeMethod
    public void superSetup() {
        System.out.println("running super");
        order.add("super");
    }

}

public class SampleTest extends SuperSampleTest {

    @BeforeMethod
    public void childSetup() {
        System.out.println("running child");
        order.add("child");
    }

    @Test 
    public void verifyOrder() {
        if (order.get(0).equals("child"))
            fail("child before method ran before super!");
    }

}
@wutingbupt
Copy link
Contributor

I try to run it in my side and both super and child are run, the order is super and child

shafr pushed a commit to shafr/docker-unit-test-framework that referenced this issue Jul 26, 2018
…lt package.

So it looks like that for annotation BeforeMethod & AfterMethod the visibility of methods is taken into accounts.

testng-team/testng#473
@krmahadevan krmahadevan added this to the 7.6.0 milestone Jan 7, 2022
@krmahadevan krmahadevan modified the milestones: 7.6.0, 7.7.0 May 18, 2022
@krmahadevan krmahadevan removed this from the 7.7.0 milestone Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants