Skip to content
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

Method predecessors lookup and/or method sorting is broken in certain inheritance and naming setups #3000

Closed
3 of 7 tasks
ptomaszek opened this issue Oct 27, 2023 · 0 comments · Fixed by #3107
Closed
3 of 7 tasks

Comments

@ptomaszek
Copy link

ptomaszek commented Oct 27, 2023

⁸### TestNG Version
7.8.0 on JDK 11 Temurin (Liniux and Windows)
maven-surefire-plugin:3.1.2
aspectjweaver:1.9.20.1

Or check out the source code: https://github.com/ptomaszek/testng-pt-playground/tree/feature/testng-7.8.0-unexpected-failure

Expected behavior

Test passes

Actual behavior

Test fails

Is the issue reproducible on runner?

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

Test case sample

Run the test (IntelliJ or mvn test) and note it fails. Then apply any solution from the comments and observe the test passes:

package com.example; // 1. to make the test PASS change to `org.example`

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static org.testng.Assert.assertNotNull;

public class MyTest extends MyBaseTest {

    @BeforeClass
    public void beforeClass() {
        assertNotNull(dependency); // fails here
    }

    @Test
    public void test() {
    }
}

abstract class MyBaseTest implements MyInterface { // 2. alternatively, to make the test PASS remove `implements MyInterface`
    protected Object dependency;

    public void setDependency(Object dependency) {
    }

    @BeforeClass
    public void setupDependency() {
        dependency = new Object();
    }

    @BeforeClass(dependsOnMethods = "setupDependency")
    public void setupAdditionalDependency_() {  // 3. alternatively, to make the test PASS remove `_` from the method name
    }
}

interface MyInterface {

    void setDependency(Object dependency);

    default Object getDependency() { // 4. alternatively, to make the test PASS remove this method
        return null;
    }
}

Something that may direct you to the solution:
Debug code at Graph:130 (at the end of topologicalSort()) and observe the object's state:

when PASS, you'll see:

m_strictlySortedNodes = {ArrayList@2282}  size = 2
0 = {ConfigurationMethod@2292} "MyTest.setupDependency()[pri:0, instance:null]"
1 = {ConfigurationMethod@2293} "MyTest.setupAdditionalDependency()[pri:0, instance:null]"

when FAIL, you'll see

m_strictlySortedNodes = {ArrayList@2283}  size = 3
0 = {ConfigurationMethod@2293} "MyTest.beforeClass()[pri:0, instance:null]" // I believe it should not be here, as the list should contain only independent (top level?) methods
1 = {ConfigurationMethod@2294} "MyTest.setupDependency()[pri:0, instance:null]"
2 = {ConfigurationMethod@2295} "MyTest.setupAdditionalDependency_()[pri:0, instance:null]"
ptomaszek added a commit to ptomaszek/testng-pt-playground that referenced this issue Oct 28, 2023
ptomaszek added a commit to ptomaszek/testng-pt-playground that referenced this issue Oct 28, 2023
ptomaszek added a commit to ptomaszek/testng-pt-playground that referenced this issue Oct 28, 2023
ptomaszek added a commit to ptomaszek/testng-pt-playground that referenced this issue Oct 28, 2023
krmahadevan added a commit to krmahadevan/testng that referenced this issue Apr 3, 2024
@krmahadevan krmahadevan added this to the 7.10.0 milestone Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants