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

Allow ITestObjectFactory injection via listeners #2677

Merged
merged 1 commit into from Nov 26, 2021

Conversation

krmahadevan
Copy link
Member

Closes #2676

Fixes #2676 .

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt
  • Auto applied styling via ./gradlew autostyleApply

We encourage pull requests that:

  • Add new features to TestNG (or)
  • Fix bugs in TestNG

If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the
TestNG-dev before you spend time working on it.

Note: For more information on contribution guidelines please make sure you refer our Contributing section for detailed set of steps.

Copy link
Member

@juherr juherr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is going weird in the internal model: it is not clear why and when we should use m_configuration.getObjectFactory()instead of m_objectFactory = suite.getObjectFactory() (or the opposite).
Any idea how we can improve it?

@krmahadevan
Copy link
Member Author

@juherr i also had the same feel. I dont have an answer on how to get it streamlined. Maybe we can take it as a separate pull request ?

On a bare essential i think we should only query the suite object for a factory because it is getting injected with a factory object from TestNG. But the only challenge i saw is when a user sets a test object factory via their test class.

Right now its a bit convoluted.

I would prefer to deal with it as a separate PR and not mix it with this feature PR.

@juherr
Copy link
Member

juherr commented Nov 22, 2021

@krmahadevan Agree to track the architecture point into another issue.

@krmahadevan
Copy link
Member Author

@juherr - I have updated the PR based on your review comments. Please help take a look.

@krmahadevan
Copy link
Member Author

@krmahadevan Agree to track the architecture point into another issue.

I have now created a new issue for tracking the architectural discrepancies as part of #2679

result = new Object[] {Dispenser.newInstance(m_objectFactory).dispense(attributes)};
result =
new Object[] {
Dispenser.newInstance(m_testContext.getSuite().getObjectFactory())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juherr - I didnt understand this comment and the link you shared is taking me to the same class. Can you please help me understand ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was not explicit enough.
You have 2 different ways to create a dispenser in the same class. Is it expected? If it is expected, could you add a comment that explains why? If it is not expected, you can share a same builder method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juherr - Yes you are right. One place is for the JUnit flow but I dont even see that codepath being executed and so I dont know why it exists even. I was first thinking that, this particular code path is going to get executed when we have junit attribute in suite set to true and I am running a bunch of JUnit tests using TestNG. But I noticed that the tests don't even take that path. It may be dead code but I cannot remove it until I know for sure. I will dig into it deeper separately and not in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From looking at the code, it looks like we perhaps never supported the notion of a test object factory for JUnit tests, because the codepath (when I execute a JUnit annotated test using TestNG) is going such that, JUnit is internally invoking the constructor of the test class and our objectfactory is not even coming into picture. I think if there are no other comments on this PR (which is to fix test objectfactory to be set for TestNG tests via listeners) we should merge this PR and deal with cleaning up the test object factory impact for JUnit tests separately (and maybe even remove the irrelevant code sections. )

Maybe I dont know enough but this is my first impression from what I see

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you ask me, I will propose to drop the junit support and advice to use https://github.com/junit-team/testng-engine when users ask for running both junit and testng.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juherr sure. So can we go ahead with merging this PR ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just add a comment that link to the current discussion ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and captured this as a defect and included all the details #2683

@krmahadevan krmahadevan merged commit e8f17fe into testng-team:master Nov 26, 2021
@krmahadevan krmahadevan deleted the fix_2676 branch November 26, 2021 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPE is triggered when working with ITestObjectFactory
2 participants