title: How to inject parameter into constructor of TestNG class?
body: <p>I have implemented a programm with the strategy pattern. So I have an interface which is used at some places and the concrete implementation may be replaced. </p>
  
  <p>Now I want to test this programm. I would like to do it in a similar way. Write a test once, which tests against the interface. The concrete interface implementation should be injected at the beginning of the test, so that I may replace it easily.</p>
  
  <p>My testclass looks similar to this one: </p>
  
  <pre><code>public class MyTestClass {
  
      private StrategeyInterface strategy;
  
      public MyTestClass(StrategeyInterface strategy) {
          this.strategy = strategy;
      }
      ....test methods using the strategy.
  }
  </code></pre>
  
  <p>The parameterized contructor must used to be inject the concrete strategy implementation at thr beginning og the tests. </p>
  
  <p>Now I did not get TestNG to run it and inject the concrete implementation instance. I tried several ways with inheritance, <code>@DataProvider</code>, <code>@Factory</code> and the corresponding methods, but without luck.</p>
  
  <p>Here is what the testNG report says:</p>
  
  <pre><code>Can't invoke public void MyClass.myTestMethod(): either make it static or add a no-args constructor to your class
  </code></pre>
  
  <p>I use the maven surefire plugin to run the tests. Here is the relevant part of the pom.xml:</p>
  
  <pre><code>    &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
                  &lt;suiteXmlFiles&gt;
                      &lt;suiteXmlFile&gt;src/test/resources/testng.xml&lt;/suiteXmlFile&gt;
                  &lt;/suiteXmlFiles&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p><strong>How do I write and run the tests, with injecting a concrete implementation into the test class?</strong></p>
  
  <p>Thanks in advance.</p>
  
  <p>P.S. I could deliver more code I tried. I did not post it here, yet, because I tried so many variants so that I am kind of confused now and all of them fail. </p>