-
Notifications
You must be signed in to change notification settings - Fork 1k
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
MavenProject coming null inside ITestContext #3141
Comments
Hi, MavenProject cannot be present if nobody adds it. |
@mehulparmariitr - Adding to what @juherr already called out. TestNG does not have any context with respect to the build tool that is executing it (which would be maven in this case). If you are just after a bunch of maven properties, then you can perhaps use the maven resources plugin as explained in this stackoverflow post and then read the properties file via your TestNG listener to get it to work. The other option would be to file a bug in the Maven surefire plugin jira page and get them to have this enabled at the maven surefire plugin side. Closing this issue since there's not much that is required to be done from TestNG side here. |
I don't want to read my properties file. Just want to read pom.xml of all modules, so therefore need to create a |
In that case, you should just add the Maven core artifact as a dependency and then directly work with it. https://stackoverflow.com/a/4838664/679824 |
Caveat there is, pom.xml location of my current module I will have to fetch from |
The properties file is also going to be generated by Maven and not going to be created by you. So when you build/test your project, the maven resources plugin kicks in and starts replacing the variables with actual values obtained from the maven context. In either case, please play around with it to get a bit more better understanding as to what it does. |
You wouldn't need to be dealing with any of that, if you just add the maven resources plugin to your parent pom and then have it do the heavy lifting for you in terms of dumping whatever maven data you need into a properties file. |
Okay I see idea is to create a template properties file and Maven will load it when maven resources plugin is kicked in root pom.xml. |
No there are no other ways. You are basically asking for awareness of a specific build tool, with a test runner. Please remember that TestNG is a test runner that can be run via a build tool (Ant/Maven/Gradle/Bazel) or it can even be run via a plain vanilla java project. So, there's no way in which TestNG can have that sort of intelligence baked into it. You have one of the following options.
|
TestNG Version
Expected behavior
iTestContext.getAttribute("maven.project")
should not be nullActual behavior
mavenProject
is coming as nullIs the issue reproducible on runner?
Test case sample
What am I missing here. I even added maven-surefire-plugin but no change.
Contribution guidelines
Incase you plan to raise a pull request to fix this issue, please make sure you refer our Contributing section for detailed set of steps.
The text was updated successfully, but these errors were encountered: