Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Issue in ITestcontext.getAllTestMethods() with annotation @BeforeSuite #2925

Closed
Prakash-QA opened this issue Jun 16, 2023 · 0 comments · Fixed by #2933
Closed

Issue in ITestcontext.getAllTestMethods() with annotation @BeforeSuite #2925

Prakash-QA opened this issue Jun 16, 2023 · 0 comments · Fixed by #2933
Milestone

Comments

@Prakash-QA
Copy link

Prakash-QA commented Jun 16, 2023

TestNG Version

7.8.0

Issue

ITestcontext.getAllTestMethods() with annotation @BeforeSuite returns the method names incorrectly from other test classes

Whole context of an issue

I have written logic to get all the enabled tests from the test classes and pass those enabled test names to other components that I use for my project.

Test cases are enabled via the testng.xml file using the <methods> tag[ with <include>] under <class>. If I don't pass <methods> tag, then all tests under that test class are enabled, and if I pass the tag, only those tests are enabled for execution.

I have 3 test classes which will have different test methods and all class should have the following code [To get the enabled test cases and pass those methods for other components in my project]

Test Class Name: CreateTests
Test Method Name: create
Test Class Name: UpdateTests
Test Method Name: update
Test Class Name: DeleteTests
Test Method Name: delete
@BeforeSuite
public void preConditionsSetUp(ITestContext preSetupContext) {
ArrayList<String> enabledTestCasesList = new ArrayList<>();
ITestNGMethod[] testNGMethod = preSetupContext.getAllTestMethods();
for (ITestNGMethod allMethods : testNGMethod) {
enabledTestCasesList.add(allMethods.getMethodName());
}
System.out.println("enabledTestCasesList in class 'UpdateTests' :: "+enabledTestCasesList);
}

My testng.xml file is like this

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="QA Test Suite" verbose="1">

<test name="CreateTest">
<classes>
<class name="testcases.module1.CreateTests"/>
</classes>
</test>
<test name="UpdateTest">
<classes>
<class name="testcases.module1.UpdateTests"/>
</classes>
</test>
<test name="Delete">
<classes>
<class name="testcases.module1.DeleteTests"/>
</classes>
</test>

</suite>

When I execute above testng.xml, enabledTestCasesList any of 3 test classes, ITestcontext.getAllTestMethods() returns the method from last test case 'delete' instead 'create','update'.

I've attached the test maven project here.

TestNGIssue.zip

TestNG Dev email conversation - https://groups.google.com/g/testng-dev/c/iM7Ot6pLyIg/m/zp3WqHq3AwAJ

krmahadevan added a commit to krmahadevan/testng that referenced this issue Jul 14, 2023
@krmahadevan krmahadevan added this to the 7.9.0 milestone Jul 14, 2023
krmahadevan added a commit to krmahadevan/testng that referenced this issue Jul 14, 2023
krmahadevan added a commit to krmahadevan/testng that referenced this issue Jul 14, 2023
krmahadevan added a commit that referenced this issue Jul 15, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants