Cyclic graph of methods when multiple tests extend the same base test class

716 views
Skip to first unread message

kevinstembridge

unread,
Mar 14, 2007, 7:06:04 AM3/14/07
to testng...@googlegroups.com
Hi folks,
First off, I only started using TestNG for the first time a couple of days ago and so far I'm very impressed, so well done. But being an absolute beginner I'm a bit stumped by a small problem I'm having.

I'm getting a "Cyclic graph of methods" error when running two tests that both extend from the same abstract superclass. Actually, there is an intermediate abstract test class that contains some @Test methods (no other annotated methods). And finally there are the two concrete test implementations that contain further @Test methods. I can run one of either of these tests without any problem but when I run them both together I get a cyclic dependency error.

The following code is a simplified version of my test classes:

public abstract class BaseIntegrationTest {

@BeforeClass(groups="integration")
protected void initIntegrationTesting() {
//...
}

@BeforeClass(groups="integration")
void executeBeforeClassDbOperations() {
//...
}

}

public abstract class AbstractGenericTests extends BaseIntegrationTest {

@Test(groups="integration")
public final void testSomething() {
//...
}

}

public class SomeConcreteTests extends AbstractGenericTests {

@Test(groups="integration")
public void testSomethingElse() {
//...
}

}


public class SomeMoreConcreteTests extends AbstractGenericTests {

@Test(groups="integration")
public void testSomethingOtherThing() {
//...
}

}

I'm using TestNG version 5.5 on JDK1.5.
The logging output and stack trace are below.
It'd be great if someone could offer some advice to point out what I'm doing wrong or maybe provide a workaround.

Cheers,
Kevin

[MethodInheritance] com.xxx.server.persist.HibernateIntegrationTest.executeBeforeClassDbOperations() DEPENDS ON com.xxx.server.persist.HibernateIntegrationTest.initIntegrationTesting()
[testng] [MethodInheritance] com.xxx.server.persist.HibernateIntegrationTest.initIntegrationTesting() DEPENDS ON com.xxx.server.persist.HibernateIntegrationTest.executeBeforeClassDbOperations()
[testng] [MethodInheritance] com.xxx.server.persist.HibernateIntegrationTest.executeBeforeClassDbOperations() DEPENDS ON com.xxx.server.persist.HibernateIntegrationTest.initIntegrationTesting()
[testng] ===============================================
[testng] Ant suite
[testng] Total tests run: 0, Failures: 0, Skips: 0
[testng] ===============================================
[testng] org.testng.TestNGException:
[testng] Cyclic graph of methods
[testng] at org.testng.internal.Graph.topologicalSort(Graph.java:122)
[testng] at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:516)
[testng] at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:568)
[testng] at org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:82)
[testng] at org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:50)
[testng] at org.testng.TestRunner.initMethods(TestRunner.java:319)
[testng] at org.testng.TestRunner.init(TestRunner.java:198)
[testng] at org.testng.TestRunner.init(TestRunner.java:168)
[testng] at org.testng.TestRunner.<init>(TestRunner.java:127)
[testng] at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:418)
[testng] at org.testng.SuiteRunner.privateRun(SuiteRunner.java:212)
[testng] at org.testng.SuiteRunner.run(SuiteRunner.java:168)
[testng] at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:987)
[testng] at org.testng.TestNG.runSuitesLocally(TestNG.java:951)
[testng] at org.testng.TestNG.run(TestNG.java:719)
[testng] at org.testng.TestNG.privateMain(TestNG.java:1019)
[testng] at org.testng.TestNG.main(TestNG.java:997)
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=70619&messageID=132406#132406

Cédric Beust ♔

unread,
Mar 14, 2007, 7:28:41 AM3/14/07
to testng...@googlegroups.com
Hi Kevin,

I'm suspecting you're not showing us all your code because I see no "dependsOnGroups".

What I think is happening is that you are creating a cyclic dependency because of a method defined in a base class.

Let me know if this is enough information to diagnose your problem, and if not, please try to trim down your code to a minimum number of classes (which should have at least one "dependsOnGroups") and post it here again.

Thanks!

--
Cedric


   [testng] [MethodInheritance] com.xxx.server.persist.HibernateIntegrationTest.executeBeforeClassDbOperations () DEPENDS ON com.xxx.server.persist.HibernateIntegrationTest.initIntegrationTesting()

   [testng] ===============================================
   [testng] Ant suite
   [testng] Total tests run: 0, Failures: 0, Skips: 0
   [testng] ===============================================
   [testng] org.testng.TestNGException:
   [testng] Cyclic graph of methods
   [testng] at org.testng.internal.Graph.topologicalSort(Graph.java:122)
   [testng] at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:516)
   [testng] at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:568)
   [testng] at org.testng.internal.MethodHelper.collectAndOrderMethods (MethodHelper.java:82)

   [testng] at org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:50)
   [testng] at org.testng.TestRunner.initMethods(TestRunner.java:319)
   [testng] at org.testng.TestRunner.init (TestRunner.java:198)

   [testng] at org.testng.TestRunner.init(TestRunner.java:168)
   [testng] at org.testng.TestRunner.<init>(TestRunner.java:127)
   [testng] at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner (SuiteRunner.java:418)

   [testng] at org.testng.SuiteRunner.privateRun(SuiteRunner.java:212)
   [testng] at org.testng.SuiteRunner.run(SuiteRunner.java:168)
   [testng] at org.testng.TestNG.createAndRunSuiteRunners (TestNG.java:987)

   [testng] at org.testng.TestNG.runSuitesLocally(TestNG.java:951)
   [testng] at org.testng.TestNG.run(TestNG.java:719)
   [testng] at org.testng.TestNG.privateMain(TestNG.java:1019)
   [testng] at org.testng.TestNG.main(TestNG.java:997)
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=70619&messageID=132406#132406







--
Cédric

kevinstembridge

unread,
Mar 14, 2007, 10:05:36 AM3/14/07
to testng...@googlegroups.com
Hi Cedric,
Thanks for the quick response.

I'm not quite sure what you mean. None of my classes have any dependsOnGroups or dependsOnMethods annotations in them. Are you saying that I am supposed to have a dependsOnGroups, or were you thinking that I must have had one in there somewhere that would be causing the error?

So, just to confirm, I'm not explicitly creating any dependencies using annotations. The error message says that one of the @BeforeClass methods defined in the top-level base class is dependent on the other @BeforeClass method in the same base class, and vice-versa. But this error only shows up when running more than one concrete test subclass at the same time.

If you give me some time I'll write some trimmed down classes to reproduce the error and attach them to this thread.

Thanks again for the reply


---------------------------------------------------------------------
Posted via Jive Forums

http://forums.opensymphony.com/thread.jspa?threadID=70619&messageID=132455#132455

Cédric Beust ♔

unread,
Mar 14, 2007, 10:47:07 AM3/14/07
to testng...@googlegroups.com
My bad, Kevin, you are right:  I was able to reproduce this bug without any depends.  I'm looking into it.

--
Cedric


On 3/14/07, kevinstembridge <testng...@opensymphony.com> wrote:
--
Cédric

kevinstembridge

unread,
Mar 14, 2007, 10:48:22 AM3/14/07
to testng...@googlegroups.com
Ok, I've attached a jar that contains some simple test classes that illustrate the problem I'm seeing. There is also an ant script to run the tests.

1. Extract the jar file somewhere, this creates a directory called testng-cyclic-dependency.
2. CD into this directory.
3. Copy testng-5.5-jdk15.jar into this directory.
4. run ant from the command line

The default ant target runs both test subclasses and shows up the error. There are also targets to run each test class individually, without errors.

I hope this helps

Cheers,
Kevin


---------------------------------------------------------------------
Posted via Jive Forums

http://forums.opensymphony.com/thread.jspa?threadID=70619&messageID=132460#132460

testng-cyclic-dependency.jar

Cédric Beust ♔

unread,
Mar 14, 2007, 11:03:50 AM3/14/07
to testng...@googlegroups.com
Kevin, I fixed the bug.  Can you try the following jar:

http://testng.org/testng-5.6beta-jdk15.jar

and let me know if it works for you?

Thanks!

--
Cedric


On 3/14/07, kevinstembridge <testng...@opensymphony.com> wrote:
--
Cédric

kevinstembridge

unread,
Mar 14, 2007, 11:32:20 AM3/14/07
to testng...@googlegroups.com
Fantastic!! Works perfectly. Thanks very much Cedric. Great response.

---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=70619&messageID=132491#132491

Reply all
Reply to author
Forward
0 new messages