question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Version 7.1.0, @BeforeGroups and @AfterGroups Annotations are not working

See original GitHub issue

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 .

  • When running the test class directly via the IDE >> the issue happens and the Groups annotations doesn’t work.
  • When running from the xml file while including the groups names in the run parameter >> the Groups annotations works fine.

Same happens with maven surefire plugin.

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans
  • Surefire plugin

Sample code to reproduce:

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");
	}
	
}

Version 7.1.0 behavior Ec7 1 0 7 1 0

Version 7.0.0 behavior Ec7 0 0 7 0 0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:36 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
cbeustcommented, Oct 22, 2021

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.

1reaction
martinaldrincommented, Oct 22, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Version 7.1.0, @BeforeGroups and @AfterGroups Annotations ...
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.
Read more >
Annotations @BeforeGroups problem - Google Groups
I have some problem with @BeforeGroups and @AfterGroups annotations. I try to run this example code. @BeforeGroups(groups = "test") public void before() {...
Read more >
[JDK-8256244] java/lang/ProcessHandle/PermissionTest.java ...
0 if there was a @BeforeGroups/@AfterGroups annotation, that method was getting executed irrespective of whether group selection was applied or not. This ...
Read more >
TestNG beforeGroups is not getting executed - Stack Overflow
My problem is that I cannot get beforeGroups (and afterGroups) to occur. My code: OrderTest.java import org.testng.annotations.AfterClass; ...
Read more >
AfterGroups (TestNG 6.8.17 API) - Javadoc.io
org.testng.annotations. Annotation Type AfterGroups ... beforeTest, beforeTestClass and beforeTestMethod, but not beforeGroups): If set to true, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found