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
Cannot inject @Test annotated Method [main] with [class [Ljava.lang.String;]. #1405
Comments
I think it's because of the fact that a class level @test annotation causes
TestNG to start treating all public methods (both static and instance ones)
as Test methods and so tries parameter injection (for parameterized methods
) which explains the error because default parameter injection doesn't know
how to deal with a String array.
|
That was my analysis as well. I think either static methods or, at least the |
True, a @cbeust WDYT? |
Sounds good to me. I often have to add |
I'd be happy using that approach if added to the exception message. I was debugging with a main method, so not a very common occurrence. |
Cannot inject @test annotated Method [main] with [class [Ljava.lang.String;] what is the solution for this issue |
@Pavithranandhini You haven't told us a lot of things.
All said and done, please check if this comment helps you fix it.
Upgrade to the latest version and this should be taken care of, because it was a bug that got fixed. |
@umeshkarkar the exception clearly gives you a link that you can consider referring to understand how to get past the problem. You have a test method that is accepting a string parameter but you have neither used a data provider nor used the TestNG is working fine. |
Yeah, got it but again im getting nullpointerException at line no 23 after removing string parameter from the test case. |
@umeshkarkar - Please use the Google forums or stackoverflow to seek help on user issues for TestNG. WE would like to confine the issues page to tracking actual TestNG bugs or new features. So I would suggest that you post on either of these two forums with a simple full fledged example that can be used to reproduce the problem and someone in the forum should be able to help you out. |
Sure. Thanks!! |
Your test method has parameters but doesn't use parameters. See the documentation: https://testng.org/#_parameters |
While understandable, I'd argue that the class annotation shouldn't apply to static methods or, at least, to the
main
method. It is easy to work around by configuring each method, but was surprising.The text was updated successfully, but these errors were encountered: