How to execute dependent test?

788 views
Skip to first unread message

Roman Fominych

unread,
Dec 19, 2016, 4:55:56 AM12/19/16
to testng-users
given following structure in two Java classes:

public class UserRegistrationTest {

        @Test(groups = { "userRegistration" })
public void registerUserSuccess(ITestContext context) {
...
        context.setAttribute("user", user);
}
}


public class UserLoginTest {

        @Test(dependsOnGroups = { "userRegistration" })
public void userLoginSuccess(ITestContext context) {
        User user = (User) context.getAttribute("user");
...
}
}



When from Intellij Idea I try to run only one test "UserLoginTest" - then test is ignored with the exception:
DependencyMap::Method "UserLoginTest.userLoginSuccess(org.testng.ITestContext)[pri:0, instance:...tests.UserLoginTest@25618e91]" depends on nonexistent group "userRegistration"


Problem is:
Test developer should be able to run only one test without running all the suite, for test development or test debug purposes. How to make that dependent test run?

Roman Fominych

unread,
Dec 19, 2016, 5:38:30 AM12/19/16
to testng-users
So I see this difference between "dependsOnMethods" and "dependsOnGroups"

"dependsOnMethods":
- dependent method and his "parent" should be in THE SAME class
- when running dependent method only in Intellij Idea - dependencies are automatically resolved, and "parent" is run before dependent method

"dependsOnGroups":
- dependent method and his "parent" can be in different classes
- when running dependent method only in Intellij Idea - dependencies are NOT automatically resolved, exception occurs and test is marked as "Ignored"

Roman Fominych

unread,
Dec 19, 2016, 5:41:34 AM12/19/16
to testng-users
To put all methods to one class is unreasonable

So still trying to figure out how to automatically resolve dependencies between multiple classes when running only one test that has "dependsOnGroups"

Cédric Beust ♔

unread,
Dec 19, 2016, 12:36:41 PM12/19/16
to testng...@googlegroups.com
FYI, there is extra code in TestNG to do this (if you just run this method from the command line, TestNG should correctly include all the methods depended upon, whether it's a group or a method dependency).

I suspect the IDEA plug-in doesn't implement that logic.


-- 
Cédric


On Mon, Dec 19, 2016 at 2:41 AM, Roman Fominych <r.fom...@gmail.com> wrote:
To put all methods to one class is unreasonable

So still trying to figure out how to automatically resolve dependencies between multiple classes when running only one test that has "dependsOnGroups"

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Roman Fominych

unread,
Dec 20, 2016, 4:44:55 AM12/20/16
to testng-users
To clarify, the exact problem is not "ability to run one dependent test", but "ability to run one dependent test using Intellij Idea" - so dependent test can be easily debugged using IDE

So now it looks like Intellij Idea plugin supports only "dependsOnMethods", but not "dependsOnGroups" (for the purpose of executing particular test), this means Intellij Idea is not fully supporting TestNG. Looks like plugin first collects methods to run, then collects their groups, then tries to resolve group dependencies - and fails in case referenced group is not already collected (as in the case with running one particular test)

As a result test with "dependsOnGroups" can be debugged only when test is run using command line and Remote Debugger is attached to the test, kind of cumbersome solution...

To sum up, inability to easily debug such tests in IDE makes "dependsOnGroups" unusable at least for Intellij Idea+Maven (and "dependsOnMethods" is already unusable since it can only be used inside one class)

It's interesting if this problem exists only for Intellij Idea+Maven pair... Interesting how other people are debugging TestNG dependent tests...

Roman Fominych

unread,
Dec 20, 2016, 5:15:07 AM12/20/16
to testng-users
IDEA-141621
Add a way to run a single TestNG test which has dependencies

so there is issue created more than year ago

Cédric Beust ♔

unread,
Dec 20, 2016, 2:23:41 PM12/20/16
to testng...@googlegroups.com
That was my point: I think it's an IDEA plug-in issue, not a TestNG one.


-- 
Cédric


--
Reply all
Reply to author
Forward
0 new messages