Open chetand24 opened 6 years ago
@chetand24 - There are two parts to your issue.
The Before and After methods are not running when "include" tag present in the testng suite.
By default if you would like your BeforeXXX
and AfterXXX
to be executed all the time, irrespective of what group is being executed, you should be using setting : alwaysRun=true
But is working fine when "exclude" is present
This part is a bug. I have fixed this, by raising a pull request ( https://github.com/cbeust/testng/pull/1575 )
@krmahadevan I'm not sure if it is a bug. The documentation doesn't specify it, but we can imagine that no group means the "default group".
So, include "x" won't add "default group" but exclude "x" won't remove "default group".
@cbeust Could you clarify the expected behavior of "exclude" for methods without a group?
In fact, if we remove "no group" methods with "exclude", I don't know how to run "no group" and some other groups methods.
@juherr - You are right in terms of the behavior not defined properly.
Here's my understanding :
default
/default group
groups (similar to how we have a default
package when we don't specify the package name for a class) in TestNG. no group
(or) default
group with include
doesn't work any way because a user cannot combine methods with groups specified and methods with no groups specified together in the single execution via groups mechanism. Not at-least with the @Test
methods. So the behavior should be consistent for exclude
as well. @krmahadevan, your PR will broke backward compatibility. In my projects I use groups feature only to exclude tests (flacky, app-bug, time-consumind, etc). So I mark only those tests which I want to exclude. After your PR all my tests without groups will be excluded from run. I'll be forced to assign some groups to ALL methods when I want to exclude just 1 test-case. This is not obvious (I need to assign ANY group to method if I want to run it with exclusions activated) I'll try to rectify your understanding:
About
Currently
no group
(or)default
group withinclude
doesn't work any way because a user cannot combine methods with groups specified and methods with no groups specified together in the single execution via groups mechanism.
Test with no-group belongs to virtual 'all-tests' group (as same as tests with groups). No need to include
something into this group because it already contains all stuffs. But if you still want to combine (no-group)
and some-group
then probably you just need one more group like common-tests
for such tests.
P.S. Of cause, you always can write custom filter to override default behavior of XmlMethodSelector
@kool79 - Thanks for your inputs. The only reason why this PR is pending merge and will perhaps never be merged is because of backward compatibility. The current behavior IMHO is not intuitive.
Methods which dont belong to a group, mean they dont belong to a group. There cannot be a virtual all-tests
group to which they get automagically added.
But debates apart, backward compatibility is more important than anything else. So this PR will not be merged.
It almost begs the question if alwaysRun should default to true and be disabled if the method has a group.
TestNG Version : 6.12.0, 6.11.0
Expected behavior
The Before and After methods should run when "include" tag is present in the testng suite
Actual behavior
The Before and After methods are not running when "include" tag present in the testng suite. But is working fine when "exclude" is present
Is the issue reproductible on runner?
Test case sample
The test class:
Example XML Suite
Output when included the group:
Output when excluded the group: