How to include only specific methods in TestNG using a Factory
<p>With TestNG it's possible to include/exclude specific methods in the testng xml file as follows:</p>

<pre><code>&lt;classes&gt;
  &lt;class name="WebTest"&gt;
    &lt;methods&gt;
      &lt;include name="testMethod1"/&gt;
    &lt;/methods&gt;
  &lt;/class&gt;
&lt;/classes&gt;
</code></pre>

<p>When using a factory to provide instances of <code>WebTest</code> the documentation states that you should only include the factory class in the xml, as follows:</p>

<pre><code>&lt;classes&gt;
  &lt;class name="WebTestFactory" /&gt;
&lt;/classes
</code></pre>

<p>The problem is that when using a factory, TestNG runs all annotated methods of the class <code>WebTest</code>. What I'd like to do is something like this:</p>

<pre><code>&lt;classes&gt;
  &lt;class name="WebTestFactory"&gt;
    &lt;methods&gt;
      &lt;include name="testMethod1"/&gt;
    &lt;/methods&gt;
  &lt;/class&gt;
&lt;/classes&gt;
</code></pre>

<p>Where <code>testMethod1</code> is a method belonging to the class <code>WebTest</code>, and where instances of <code>WebTest</code> are returned by the <code>WebTestFactory</code>.</p>

<p>However, whenever I try this TestNG complains that <code>WebTestFactory</code> does not include <code>testMethod1</code>.</p>

<p>Is there a way to specify method inclusion / exclusion in the XML file when using a factory with TestNG?</p>