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

BDD style tests using inner classes #534

Open
jillesvangurp opened this issue Jul 10, 2014 · 0 comments
Open

BDD style tests using inner classes #534

jillesvangurp opened this issue Jul 10, 2014 · 0 comments

Comments

@jillesvangurp
Copy link

I was thinking to use BDD style testing with testng by using inner classes. This nearly works except the order of things messes up the intended behavior so I was wondering if this is something worth fixing in testng.

In the test below the first given never executes because there is no test method in the outerclass. If you add one it does execute but at the wrong time only after the innner tests run. So beforeclass is actually running at the wrong time (bug?).

I realize that this is stretching the original design goals a bit but it might actually be kind of neat if this could be made to work. It would basically allow for BDD style tests.

There seem to be two issues that prevent this from working.

  1. Classes labeled with @test never execute their @BeforeClass method unless they have test methods.

  2. Inner classes are not really part of the test and so inner and outer methods are executed in the wrong order. The outer given actually executes after the tests of the inner classes run. With @before I get similar results.

A related issues might be #475

@Test
public class BddTest {
    @BeforeClass
    public void given() {
        System.out.println("given some shared stuff");
    }

    @Test
    public static class DescribeSomeFunctionality {

        @BeforeClass
        public void given() {
            System.out.println("given some more specific stuff ");
        }

        public void itShouldDoFoo() {
            System.out.println("foo");
        }

        public void itShouldDoBar() {
            System.out.println("bar");
        }

    }

    @Test
    public static class DescribeSomeMoreFunctionality {
        @BeforeClass
        public void given() {
            System.out.println("given some other stuff ");
        }

        public void shouldRunThisToo() {
            System.out.println("bar");
        }
    }
}
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

1 participant