testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.98k stars 1.02k forks source link

Change dependOnMethods using IAnnotationTransformer doesn't work as expected #1551

Open k0923 opened 7 years ago

k0923 commented 7 years ago

TestNG Version

6.12


public class MethodDependencyTest {
@Test
public void testA(){

}

@Test(dependsOnMethods = "testA")
public void testB(){

}

@Test(dependsOnMethods = "testB")
public void testC(){

}

}

now i run testC function and i have already had IAnnotationTransformer configurated which will change dependsOnMethods from "testB" to "testA"

### Expected behavior
testA will be run first and then testC will be run

### Actual behavior

org.testng.TestNGException: com.apitest.nglisteners.MethodDependencyTest.testB() is depending on method public void com.apitest.nglisteners.MethodDependencyTest.testA(), which is not annotated with @Test or not included. at org.testng.internal.MethodHelper.findDependedUponMethods(MethodHelper.java:111) at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:216) at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:292) at org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:59) at org.testng.TestRunner.initMethods(TestRunner.java:504) at org.testng.TestRunner.init(TestRunner.java:282) at org.testng.TestRunner.init(TestRunner.java:252) at org.testng.TestRunner.(TestRunner.java:192) at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:625) at org.testng.SuiteRunner.init(SuiteRunner.java:230) at org.testng.SuiteRunner.(SuiteRunner.java:173) at org.testng.TestNG.createSuiteRunner(TestNG.java:1400) at org.testng.TestNG.createSuiteRunners(TestNG.java:1380) at org.testng.TestNG.runSuitesLocally(TestNG.java:1234) at org.testng.TestNG.runSuites(TestNG.java:1161) at org.testng.TestNG.run(TestNG.java:1129) at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72) at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)


### Is the issue reproductible on runner?

- [ ] Shell
- [ ] Maven
- [ ] Gradle
- [ ] Ant
- [ ] Eclipse
- [ ] IntelliJ
- [ ] NetBeans

### Test case sample
> Please, share the test case (as small as possible) which shows the issue
jigyasa-at-git commented 6 years ago

I am facing this same issue. I have a very specific requirement:

I need to run tests by not repeating/ re-writing the dependent classes in < classes > in the testing.xml

I have researched my issue extensively and only when I didn’t find solution, I am writing this question. I hope I have provided all info needed to help me find solution.

The sample project has been added here: https://github.com/jigyasa-at-git/testngDependencyManagement/tree/master/dependencyManagement

Setup:

Original Testing.xml: (this is what I want to work)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Dependencies">
    <test name="Test 1">
        <classes>
            <class name="ClassOne" />
            <class name="ClassTwo" />
        </classes>
    </test>
    <test name="Test 2">
        <classes>
            <class name="ClassThree" />
        </classes>
    </test>
    <test name="Test 3">
        <classes>
            <class name="ClassFour" />
        </classes>
    </test>
</suite>

Issue: I am getting the following error when I run the above testing.xml:

org.testng.TestNGException: DependencyMap::Method "ClassThree.classThree_Test1()[pri:0, instance:ClassThree@475530b9]" depends on nonexistent group "classTwo"

On the other hand, it works if the testing.xml is updated like so:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Dependencies">
    <test name="Test 1">
        <classes>
            <class name="ClassOne" />
            <class name="ClassTwo" />
        </classes>
    </test>
    <test name="Test 2">
        <classes>
            <class name="ClassOne" />
            <class name="ClassTwo" />
            <class name="ClassThree" />
        </classes>
    </test>
    <test name="Test 3">
        <classes>
            <class name="ClassOne" />
            <class name="ClassTwo" />
            <class name="ClassThree" />
            <class name="ClassFour" />
        </classes>
    </test>
</suite>

Tests run fine, but then I face another problem … those classes (ClassOne, ClassTwo and ClassThree) run multiple times since they are mentioned in all 3 < test >

I have googled (including this site) this issue a lot but am not able to find any solution. Would really appreciate any help. I am stuck badly. I need a way to resolve dependencies without making the classes to run multiple times or having to manually add them to the < classes >

krmahadevan commented 6 years ago

@jigyasa-at-git - Your scenario I think is not the same as what is described in this bug. I remember you had posted this as a query on stackoverflow, wherein I had opined that this is not supported out of the box in TestNG and you will need to employ some tricks to get this done. In either case, I dont think your scenario is a bug in TestNG. TestNG is working as designed in your case. You can raise a separate issue about your problem, but this issue will not cover your scenario

jigyasa-at-git commented 6 years ago

@krmahadevan Yeah, and on stackoverflow, I had asked about some example cause I am not sure what you mean cause just googling ISuite examples was not helping me. I really need some guidance on how to make my scenario work.

And in this example, dependOnMethods is used and I am using dependsOnGroups. Rest everything is same.

krmahadevan commented 6 years ago

@jigyasa-at-git - You are asking for dependencies across <test> tags and I don't think this issue #1551 is talking about that. AFAIK, dependencies across <test> tags is not available. Please file a separate issue and we can discuss more. I dont want us to hijack this issue. Hope that makes sense.