-
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
Order for DependsOnGroups has changed after TestNg 7.4.0 #2664
Comments
After some more investigation I found the commit |
@martinaldrin - I didnt quite understand the issue here from the sample that you shared. How is the test being run? What does the suite xml file look like ? Also can you please add the expected and the actual output as well ? |
The problems is that the sorting on depends on doesn't not work on master. |
@martinaldrin - The configurations are defined as being part of groups. So So if you are running from within the IDE, then you are just running the test class without any groups. And hence the |
But that is a non backward compatible change. similar to what we raised for beforeGroups. |
@krmahadevan the issue is not just dependsOnGroups. its also fails for dependsOnMethods like the following should fail:
Should result in execution order: s3 s2 s1 but does not on since the commit #2503 basically dependsOnMethods and dependsOnGroups does nothing for all configuration methods right now, It has worked in all released TestNG versions replacing "BeforeSuite"(or any other config method) with "Test" seems to work so it only an issue for configuration methods. |
The below test runs fine when executed against import java.io.File;
import static org.assertj.core.api.Assertions.assertThat;
import org.testng.TestNG;
import org.testng.annotations.Test;
public class IssueTest {
@Test
public void testMethod() {
TestNG testng = new TestNG();
testng.setTestClasses(new Class[]{SampleTestClass.class});
testng.run();
File file = new File(
TestNG.class.getProtectionDomain().getCodeSource().getLocation().getFile());
assertThat(file.getName()).isEqualTo("testng-6.14.3.jar");
String[] expected = new String[]{"s3", "s1", "s2", "test3"};
assertThat(SampleTestClass.logs).containsExactly(expected);
}
} |
on master it will run in following order "s1, s2, s32 instead of "s3, s1, s2" |
Sorry if we confused you. the problem seems to only affect DependsOnGroups, not DependsOnMethod.
|
Yes, because when you run from within the IDE, you basically are not using groups. The javadocs for
So when we are running from within the IDE, group filtering is not getting applied. @cbeust - Am back with the same question again. I have always been under the assumption that anything that involves or is associated with groups is meant to be applicable only when running with group filtering enabled. From within IDE, thats not the case. What should be the behaviour for @juherr - WDYT ? |
Hi @krmahadevan The javadoc does not say anything about filtering in suite xml is required. And in this case, you did not skip them, you just ignored the sorting of the configuration methods that have dependsOnGroups. |
Just to ensure that we sort of the difference of opinions is why I am asking for inputs from @cbeust who has built TestNG so that the confusions are sorted out.
The way i see this is that it is applicable only when groups are enabled. including or excluding groups is exactly that. Lets say there are 3 methods as below : @Test public void foo() {}
@Test (groups="a") public void bar() {}
@Test(groups="b") public void fooBar() {} The way that I am seeing this is that,
This is why I need this to be clarified once and for all and we add tests so that this discrepancy in terms of understanding the behaviour goes away. There were no tests which iterates the behaviour that you are suggesting, else my earlier PR would have broken some changes. Which is what is making me wonder, are we looking at undocumented behaviour ? |
Hi @krmahadevan But in my opinion it is not unclear, because of.
|
Like I said before, I would like to wait to hear back from @cedricrefresh before deciding on what should be the way forward. We both are basically stating two different perspectives at how the feature should work like and I dont think its going to go anywhere till we arrive at a consensus which is where I need @cedricrefresh inputs. |
Hi again, I understand that you will sort this out first, I just wanted to give my view on it and input to the issue which I hope make it easier to to take a good decision. After more digging, I understand that #2503 was implemented to solve issues that was introduced in #2432 |
If confirmed, I think the issue should be fixed when About groups:
As a user, it took me a lot of time to understand it because it is not what I expected. @Elisedlund-ericsson @martinaldrin Guys, the feature you are asking for doesn't exist in TestNG yet and the documentation is not precise enough. |
We have had this behavior us long I have used TestNg and is working up to TestNg 7.4, but the sorting was disabled in #2503. which has not yet been released. My understanding both from code and documentation is that sorting did not care about the group filtering until recently. I'm pretty sure that this change will affect plenty of users, and also #2432. I hope the old behavior could be restored, and more unit tests could make protect this to happen again. |
DependsOnMethod can never replace DependsOnGroup, maybe in my simple example, but not in the reality. |
Maybe not but they are 2 different issues and there is no debate or design problem with DependsOnMethod -> easier to fix |
The problem is all about #2432 Which change the whole behavior, saying that you can add methods with dependsOn methods that does not exists. #2503 does not solve the issue, just ignore sorting if group in suite xml is not enabled. So allowing #2432 is very dangerous in my opinion and should not be the default behavior, if we want that as a feature I would prefer that we add an property to support that. Because that will allow us to define group dependencies that does not exists. |
Sorry, I misunderstood #2432, that should of course work as well. |
As I understand it When we add back the sorting based on groups we get cyclic dependencies. If the methods are spread out to different classes. And as I understand it the problem is this method, where a a method dependency is added to solve issues that methods in base classes are executed before the methods in the test classes. And If we add group dependsOn we get duplicated dependencies which give the cyclic dependencies. I think the solution could be that we only add one dependency, if we have a group dependency that needs to get higher priority than the dependencies between classes. |
@martinaldrin I think you got some part of the design issue. |
Hi @juherr, Yes I understand part of the problem now. but I have no clue about how to solve it and I guess I will need your expert help to solve it. Yes I will add more unit tests to my PR. |
But after more digging. I actually think the behavior that we try to protect in test.configuration.issue2432.IssueTest is wrong.
I belive that following behaviour is correct:
both prepareConfig and prepareConfigForTest1 have the group "prepareConfig" and therefor I they should be executed first regardless of which class they are in. If we don't want that that behavior I think the groups between the classes should be different. otherwise it will not be possible to define groups into different classes. |
I created a separate PR where I use my priority implementation to handle the class hierarchy sorting. I know that this is not a perfect solution either, the best would be to have a separate priority handling for class hierarchy to not interfere with user configurations. But at least I show that this could work in a different way without affecting dependsOnGroups. I believe that configuration like, dependsOnMethod, dependsOnGroup, Priority should have higher priority than the sorting on naming and class hierarchy. |
One more PR, showing an alternative solution where I use a different priority to not interfere with the user configurations. So please let me know which solution you prefer and I will try to finalize that one. and divide my changes into smaller commits. |
@martinaldrin Thanks for all your contributions.
To be honest, I've no idea how to deal with it because, except for selection, the groups feature is not yet clearly designed and may be difficult to integrate into the current base code. |
@juherr I think it works pretty well for everything except for one that was recently implemented after 7.4 release. I also believe that current implementation is quite dangerous, adding dependsOnMethod internally could definitely give some strange behavior since it can interfere with users configuration. Adding an internal priority would be much nicer here, since that can never interfere with the user configuration and just make a more soft sorting that users can override easily.
|
TestNG Version
7.5 not working
7.4 works
Expected behavior
s3
s1
s2
Actual behavior
s1
s2
s3
Is the issue reproducible on runner?
Test case sample
Here is an example for BeforeSuite, but the same problem exists for all configuration methods. The same issue also for dependsOnMethod
I have tried to find the commit where the fault was introduced, but my IDE did not like to switch gradle version and I'm new at gradle.
The text was updated successfully, but these errors were encountered: