testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.98k stars 1.02k forks source link

@BeforeGroups ignores dependsOnGroups #2804

Open schroeca opened 1 year ago

schroeca commented 1 year ago

TestNG 7.1.0

Note: only the latest version is supported

Expected behavior

The method annotated with @beforeGroups and all tests included in the defined group shall not be executed until all tests of the group on which the current group depends have finished. This includes also the @beforeGroups and @afterGroups method associated with the defined "depends on" group.

Actual behavior

The beforeGroups method and the tests included in group A are called after the beforeGroups method and the tests of group B. But group A is defined as "dependsOnGroup B".

Is the issue reproducible on runner?

Test case sample

package playground.TestNgExperiments;

import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;

public class TestGroupDependsOnGroup {

    @BeforeGroups(groups = "A1", dependsOnGroups = "B1")
    public void beforeGroupA()
    {
        System.out.println("before group A");
    }

    @AfterGroups(groups ="A1")
    public void afterGroupA()
    {
        System.out.println("after group A");
    }

    @BeforeGroups(groups = "B1")
    public void beforeGroupB()
    {
        System.out.println("setup for Group B");
    }

    @Test
    public void NoGroup()
    {
        System.out.println("GroupDependsOnGroup.NoGroup");
    }

    @Test(groups = "A1")
    public void GroupATest()
    {
        System.out.println("GroupDependsOnGroup.GroupATest");
    }

    @Test(groups = "A1")
    public void GroupATest1()
    {
        System.out.println("GroupDependsOnGroup.GroupATest1");
    }

    @Test(groups = "B1")
    public void GroupBTest()
    {
        System.out.println("GroupDependsOnGroup.GroupBTest");
    }
}

Intellij output

before group A
GroupDependsOnGroup.GroupATest
GroupDependsOnGroup.GroupATest1
after group A
setup for Group B
GroupDependsOnGroup.GroupBTest
GroupDependsOnGroup.NoGroup

===============================================
Default Suite
Total tests run: 4, Passes: 4, Failures: 0, Skips: 0
===============================================

Process finished with exit code 0
krmahadevan commented 1 year ago

@schroeca - Do you know if this ever worked? I have been searching through the codebase to find any evidence of this working and so far its been a dead end. Couldn't even find a single test also that vets this out. So if you know in which version it worked, it would be good if you could please share that information so that I can dig in from there.

schroeca commented 1 year ago

I got feedback from my team colleague that it was working in 7.0.4.

I have tested this by myself with various different versions for the past 3 weeks and it was never working.

I guess the test case my colleague used for testing was simply wrong.

Would it be possible to add the described "expected" behavior in one of your next releases?

krmahadevan commented 1 year ago

@schroeca - Thanks for the quick turnaround. This issue is going to be a bit more complicated to fix, so please bear with the delay.

I will first try and cross compare the behaviour for @Test method. The behaviour for this also should be on par with how @Test with groups and dependsOnGroups behaves in terms of group selection, and it would also have all the behaviour of a configuration annotation