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.

If @beforeMethod or @afterMethod fails then all children of the same base class will be skipped

See original GitHub issue

I’ve made an example to reproduce the issue: https://github.com/smaant/testng-bug-example

Description

Case#1 - normal behaviour

There’re two independent classes: Class1 and Class2. Class1 has an @afterMethod methods and for some reason it fails. All the rest method of the Class1 will be skipped in this case and Class2 will be executed as usual.

Case#2 - unexpected behaviour

There’re two classes: Class1 and Class2 and they have one common parent SuperClass. Class1 has an @afterMethod method and for some reason it fails. In this case the rest of the Class1 methods will be skipped AND (unexpected part) all methods of the Class2 will be skipped too.

In example I’ve added one more super class with one child to demonstrate it will be actually executed, because of another parent.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
drkthngcommented, Jul 27, 2015

Problem with children being skipped when one child fails during its own @beforeClass method still holds, if children have @beforeClass and the parent class has @beforeClass AND @afterClass. When you remove @afterClass in parent class, everything works fine, no non-failing children are skipped.

0reactions
juherrcommented, Jul 27, 2015

@drkthng Could you add your test case in TestNG tests (or update them) in a PR? See the test.inheritance package.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TestNG: All subsequent Test classes are skipped when ...
I need the @BeforeClass in the TestBase class to provide setup that all testclasses will need and I don't want to repeat in...
Read more >
Combination of @BeforeClass and @BeforeMethod causes ...
When a @BeforeClass in a child class fails, and a @BeforeMethod exists in a base class shared with another class all end up...
Read more >
BeforeMethod/@AfterMethod(onlyForGroups) methods did not ...
Its an interesting observation if you change onlyforgroups to groups then everything works: but when there are multiple groups included in ...
Read more >
TestNG - Test LifeCycle Annotations - HowToDoInJava
Lifecycle Methods in Parent and Child Classes ... it belongs to, or even if one or more methods invoked previously failed or was...
Read more >
TestNG
@BeforeMethod @AfterMethod, Configuration information for a TestNG class: @BeforeSuite: The annotated method will be run before all tests in this suite have ...
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