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

regular expression in "dependsOnMethods" not work #141

Closed
missedone opened this issue Dec 4, 2011 · 7 comments · Fixed by #2838
Closed

regular expression in "dependsOnMethods" not work #141

missedone opened this issue Dec 4, 2011 · 7 comments · Fixed by #2838

Comments

@missedone
Copy link
Contributor

hi, cbeust

I read the user guide

Both dependsOnGroups and dependsOnMethods accept regular expressions as parameters.

so i tried to use regular expression in "dependsOnMethods", for example:

@Test
public void testMethod1() {...};

@Test
public void testMethod2() {...};

@Test (dependsOnMethods="test.*")
public void testMethod3() {...};

but i got an error below:

org.testng.TestNGException:
example.testMethod3() depends on nonexistent method test.*
at org.testng.internal.MethodHelper.findDependedUponMethods(MethodHelper.java:98)

though the workaround is quit straightforward, just let you know this issue.
thanks

@wutingbupt
Copy link
Contributor

Hi missedone,

From the source code, I see that test ng using Pattern.matches(regexp, methodName) to check if current method should be invoked.

At there, the methodName is like "package name.classname. methodname"
so your regular pattern can not match this, you can add your package name and class name in this pattern, or using
.test.

Brs,
Tim

@wutingbupt
Copy link
Contributor

I think using find is better compared with matches.

@cbeust Do you have any comments for this problem?

@freddy33
Copy link

Using TestNG 6.8

Hi liked this feature, looked good on the user guides but:

  • Liked described here using "test." send:
    org.testng.TestNGException:
    org.artifactory.storage.db.build.BuildsTest.fullDelete() depends on nonexistent method test.

    at org.testng.internal.MethodHelper.findDependedUponMethods(MethodHelper.java:114)
    at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:240)
    at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:317)
    at org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:59)
    at org.testng.TestRunner.initMethods(TestRunner.java:481)
  • Using ".BuildsTest.test." send:
    java.lang.NullPointerException
    at org.testng.DependencyMap.getMethodDependingOn(DependencyMap.java:54)
    at org.testng.TestRunner.createDynamicGraph(TestRunner.java:1068)
    at org.testng.TestRunner.privateRun(TestRunner.java:734)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
    at org.testng.TestNG.run(TestNG.java:1031)
  • Using ".test." send:
    org.testng.TestNGException:
    The following methods have cyclic dependencies:
    BuildsTest.fullDelete()[pri:0, instance:org.artifactory.storage.db.build.BuildsTest@34f7dd13]
    at org.testng.internal.Graph.topologicalSort(Graph.java:148)
    at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:261)
    at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:317)
    at org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:59)
    at org.testng.TestRunner.initMethods(TestRunner.java:481)
    at org.testng.TestRunner.init(TestRunner.java:235)
    at org.testng.TestRunner.init(TestRunner.java:205)
    at org.testng.TestRunner.(TestRunner.java:160)

Looks like I'll need to dive into the code for having what I need ;)

@syntastical
Copy link

yeah this still seems broken.
I'm getting Method "DatadogLogTests.asdf()[pri:0, instance:XXX]" depends on nonexistent method "Test_C[0-9]{7}"

And my test looks like

    @Test(dependsOnMethods = "Test_C[0-9]{7}")
    public void asdf() {
        System.out.println("test");
    }
    @Test
    public void Test_C6390323() { ... }

@krmahadevan
Copy link
Member

@syntastical you tried in version 7.6.1 correct?

@syntastical
Copy link

@krmahadevan yeah we're on 7.6.1. The problem seems to be around https://github.com/cbeust/testng/blob/cd85bcb7afebbaecd2299cbc72632e27f89a441b/testng-core/src/main/java/org/testng/DependencyMap.java#L56

When it gets here "methodName" is the regex Test_C[0-9]{7} and it cannot match the dependencies in the List.

@krmahadevan
Copy link
Member

@syntastical - Would you be willing to help file a pull request for this (Since you seem to have spent time and effort in debugging this)? We can help you get it reviewed/merged.

krmahadevan added a commit to krmahadevan/testng that referenced this issue Nov 23, 2022
@krmahadevan krmahadevan added this to the 7.6.2 milestone Nov 23, 2022
krmahadevan added a commit to krmahadevan/testng that referenced this issue Nov 28, 2022
krmahadevan added a commit to krmahadevan/testng that referenced this issue Nov 28, 2022
krmahadevan added a commit to krmahadevan/testng that referenced this issue Nov 29, 2022
krmahadevan added a commit to krmahadevan/testng that referenced this issue Dec 2, 2022
krmahadevan added a commit that referenced this issue Dec 2, 2022
@krmahadevan krmahadevan modified the milestones: 7.6.2, 7.7.0 Dec 6, 2022
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.

5 participants