-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Version 7.1.0, @BeforeGroups and @AfterGroups Annotations are not working #2229
Comments
I can reproduce the same issue on my environment as well. Working on TestNG 7.0.0 |
@MahmoudElSharkawy - Can you please help with the following:
|
@krmahadevan
Same happens with maven surefire plugin. Sample code:package testNG;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
public class TestGroupsAnnotations {
@BeforeGroups(groups = "testGroup1")
public void beforeGroups1() {
System.out.println("Test Before Groups Annotation");
}
@AfterGroups(groups = "testGroup1")
public void afterGroups1() {
System.out.println("Test After Groups Annotation");
}
@Test(groups = "testGroup1")
public void test1() {
System.out.println("Test #1");
}
@Test(groups = "testGroup2")
public void test2() {
System.out.println("Test #2");
}
@Test(groups = "testGroup1")
public void test3() {
System.out.println("Test #3");
}
@Test(groups = "testGroup2")
public void test4() {
System.out.println("Test #4");
}
@BeforeGroups(groups = "testGroup2")
public void beforeGroups2() {
System.out.println("Test Before Groups Annotation #2");
}
@AfterGroups(groups = "testGroup2")
public void afterGroups2() {
System.out.println("Test After Groups Annotation #2");
}
} |
@MahmoudElSharkawy - Looks like this is a problem with the TestNG eclipse plugin. You might want to log this issue in https://github.com/cbeust/testng-eclipse/issues
I didn't quite understand this part. Does this mean that you are using |
@krmahadevan Please find below two screenshots from both TestNG version from the surefire plugin execution (Both and from the same sample provided in the previous comment) |
Reproduced the same issue: TestNG (7.1.0) +Gradle public class classForExperiments {
@BeforeGroups(groups = "IT Department")
public void before_it()
{
System.out.println("This method will be executed before the execution of IT Department group");
}
@Test
public void testcase1()
{
System.out.println("HR");
}
@Test(groups= {"IT Department"})
public void testcase2()
{
System.out.println("Software Developer");
}
@Test(groups= {"IT Department"})
public void testcase3()
{
System.out.println("QA Analyst");
}
} Expected behavior: Actual: Run from IDEA (last version) |
Looks like I've faced a similar issue after upgrading to 7.1.0 |
I get the same issue after upgrading to 7.1 on maven. org.testng fail to load the dependency files. |
Folks, By default group selection is not applicable until and unless its explicitly chosen via the suite xml file. Prior to TestNG This behavior has been changed and now So if this behavior is needed to be enabled, please create a suite xml file, resort to selection of groups adding <groups>
<run>
<include name="group-one"/>
</run>
</groups> in suite xml file and then using it. Closing this issue. |
@krmahadevan is there another way for those of us who don't use a suite xml? |
@MohabMohie - This wasn't a regression to begin with. This was a bug that always existed in TestNG which was fixed. So there's no way of doing this, unless and until, you know what the groups are. If that knowledge is there, then you can very well use an implementation of On a side note, I would be curious to know as to what exists within these If you can add more details (please feel free to be as elaborate as possible) I can suggest some alternatives. |
Hi, I think we also have phased this issue now when we Testing TestNg 7.5, we are using 6.14 at the moment and are working on uplifting to latest TestNg, but it seems not possible due to this change. We have over 500 Projects and thousands of test cases in different organizations and thousands developers. It will never be possible to adapt all of the Test and as I see it is not even a possible alternative to this change. In many Test Cases we using groups to run different Before/After methods/class and we have test within the same test class with different groups and without groups. As I understand now we must specify the groups in the suite, but that will not work for us. I don't think this was a bug correction, I think that removing a very useful feature from TestNg that simplifies test cases allot. |
Thank you for stating this. I totally agree; It was a very useful feature and it's removed without introducing any useful alternatives. For what I know and understand, Annotations are meant to run in the class and no need for suits to be configured. |
We have been working hard for long time to get correction on master and PR merged and then I suddenly met this issue and adapt to other Non backward compatible changes. I'm surprised that a very nice feature is treated as a bug and removed. this makes it extremely hard to do an uplift now. We using groups in plenty places without specify them in a suite, and for regular unit tests we don't even have suites but still uses groups. In the project I'm working in we are never allowed to introduce an Non Backward Compatible change, since different projects fetched our project automatically, and if the test don't pass it will not be uplifted to any other project and get verdict -1. The projects are complied with our Framework after all tests are passed, so even biniary Non Backward compatible changes could be extremely hard to solve. So the only way to handle such change is if we could adapt all 500 projects in advanced and make them compatible with both TestNg 6.14 and 7.5 otherwise any change will not be allowed. Today we do forking on 6.14 and 7.5 to adapt to new TestNg 7.5 to allow a smoother migration, but this is really a blocker for us. |
@martinaldrin @MahmoudElSharkawy @MohabMohie Really sorry for the inconvenience. @krmahadevan Could the old behavior be implemented with listeners? |
@cedricbeust-okta - Sure I will take a look at this and find out what can be done in terms of this. |
Could someone summarize the expected behavior? If I understand well, do you want a way to run @krmahadevan Why not consider that all groups are requested when none is specified? It is already the behavior for |
This is basically what I am trying to understand as well. The But there's one caveat. These two annotations do have a
Not sure if thats true because if you specify a group then that filtering gets applied, if you dont specify groups then no filtering is applied. But these two config annotations have a special need which is to setup and tear down only at group level. If they need to be run for everything, then ideally one should be using the |
It sounds good 👍 |
Hi, Here is an simple test example on a unit test without a suite, there might be many more cases. The benefit of using Before/AfterGroups instead of Before/AfterMethod is that they are only executed once per group and not before every method. This enable that we can do time costly operations only once per group, e.g. setup a connection that is needed only for that group.
|
Regarding the alwaysRun, that will not solve it for us, even if you fix it. Since we should only run the before/afterGroup if test methods exists. Here is one more example, why before/afterGroup is very useful. If I add a groupC and not have a test method that depends on that group, BeforeGroup C will not run. The group in the suite file we use to enable/disable different groups, but if not added in suite file all groups with test methods will be executed. If we only want to run group we specify that group in the suite, or exclude one group.
The execution order, show how great this feature is in TestNg 6.14.x, beforeGroupC is excluded since not test exists and the before methods are executed just before the tests
|
As @krmahadevan explained, groups are used to select test methods. I agree the feature you want (@Before/AfterGroups methods activation depending on the tests in the suite) is great but has never existed in TestNG before. |
@martinaldrin Instead, why not move the forking effort into the implementation of the feature you want? |
Hi @juherr, forking we only do to adapt to master and waiting for PR to be merged, we don't want to maintain forks. We want to use official releases. And I also understand that many other want to get back the original behavior, since it breaks many test cases and makes it hard to uplift. And the Before/AfterGroups is a very useful feature that we don't want to lose. |
It have exists since we use it, and many other uses it. And in the documentation there is no information that Before/AfterGroups should only work if a group is defined in the suite. I hope we can get this functionality back in a similar way. Since that will help me and many other to easier migrate to latest TestNg. |
I also have issue with this missing on the latest testng (and its forsure working in previous TestNG versions!) I find it very stupid and strange that it will run the test case in with group:
but not run the before/after methods:
if it did not run the "@test(groups = **"testGroup1")" because that group was not selected I would be more understanding, as the "@test(groups = "testGroup1")" is running, to me that is the same thing as the group being active and therefor all the groups dependencies should also run |
I totally agree with @Elisedlund-ericsson. it is very strange that only Before/AfterGroups are excluded if not defined in suite xml but for all other methods they are executed. But the group filter in the suite xml applies on all methods that have the group, not only Before/AfterGroups. |
If you run this within the IDE, you are not selecting any groups. TestNG by default is built to run all test methods in a class when there are no groups. But the same is not applicable for These two annotations are supposed to be used ONLY when you are bringing in test filtering using groups and TestNG will execute these methods when the groups to which they are supposed to be part of, get executed. Not sure what the confusion is. But like I mentioned before, this annotation does have a There is no counter intuitiveness in this behaviour. |
Please be advised that irrespective of whether you create a suite xml or not, TestNG always creates one, when you run an individual test class from within an IDE. Thats how TestNG is built.
Am pretty sure that you can pass in the list of groups to which your
Not sure what you mean that it would solve this issue. You dont need to update anything. You can do this via an annotation transformer which exists for this very same reason. Let me first do the needed changes to support what I am talking about and then we can circle back to the same discussion. I have noticed that currently the |
I think we need your help to clarify what is supposed to be the exact behaviour of this configuration annotations since you have more insights into this than me. |
Krishnan, At this point, I think what the original intent is or was is irrelevant (assuming there was even one :-)). Quite a few users seem to rely on the old behavior so we should find a way to restore it. And if we can't make this consistent with the current design, I think it would be fine to have a special flag just to enable this behavior, so that new users don't rely on it accidentally but old users can still use it. |
Hi, For me a property would be fine, because that allow us to keep using a very nice feature. I did a quick test, just by adding false in this method, my example test that I provided pass and running as expected.
|
Why not submit a pull request with these changes @martinaldrin since you already have the fix |
Hi,
|
Closes testng-team#2229 Ensure that BeforeGroups and AfterGroups config Methods always get invoked irrespective of whether Group level filtering being done by users.
Closes testng-team#2229 Ensure that BeforeGroups and AfterGroups config Methods always get invoked irrespective of whether Group level filtering being done by users.
Closes #2229 Ensure that BeforeGroups and AfterGroups config Methods always get invoked irrespective of whether Group level filtering being done by users.
I believe that this issue is a regression as they are working normally on version 7.0.0
TestNG Version
7.1.0
Expected behavior
The @BeforeGroups and @AfterGroups should be working properly when triggering the execution from a TestNG class, xml file or surefire plugin.
Actual behavior
The @BeforeGroups and @AfterGroups are not working when executing the the run from a TestNG class or from the surefire plugin, only works when the test is triggered from a testng.xml file when I include the group name in the run parameter.
Is the issue reproductible on runner?
I'm running the test class directly via the IDE [Eclipse] and via the cmd using surefire plugin .
Same happens with maven surefire plugin.
Sample code to reproduce:
Version 7.1.0 behavior
Version 7.0.0 behavior
The text was updated successfully, but these errors were encountered: