Search code examples
javaeclipseannotationsautomated-teststestng

Cannot inject @Test annotated Method [over] with [class io.appium.java_client.AppiumDriver]


Cannot inject @Test annotated Method [over] with [class io.appium.java_client.AppiumDriver].

getting this error

Cannot inject @Test annotated Method [over] with [class io.appium.java_client.AppiumDriver].

TestNG.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test   verbose="2" preserve-order="true" thread-count="5" name="Test">
  
  
   <classes>
            <class name="Apps.Utilshelper">
               
            </class>

            <class name="Apps.SGH">
                <methods>
                    <include name="Capabilities"/>
                    
                </methods>
                  </class>
                  
                  <class name="Apps.Overview">
                <methods>
                    <include name="over"/>
                    
                </methods>
                  </class>
            
            
            
            
              </classes>
            
  
  </test> <!-- Test -->
</suite> <!-- Suite -->

can anyone help it is not working


Solution

  • You marked your class with @Test annotation which made all the methods in the class to be test methods.

    You cannot just define any parameter within your test method. You have to deal with injection mechanism.

    • Either to use dependency injection mechanism that would inject some internal TestNG objects so that you could have access to the execution context, and so on (btw your error message suggests you to visit the URL for that topic)

    • Or use parameter providers that would supply your test methods with the parameter values for each run.

    If you have that method just as utility one that has not be executed as a test, then either use per-test annotation approach (so that you have only real tests annotated) or take that method to different class.