title: How to run PowerMock on dynamically created TestCase
body: <p>I was trying to mock my test suites. My test framework creates test cases by scanning test files on disk. So each time the test cases are dynamically created.
  I was trying to use PowerMock. Below is the thing I tried first.</p>
  
  <pre><code>public class GroupTestcase_T extends TestSuite {
       static void run() {
           scan();
           junit.textui.TestRunner.run(g);
       }
       static void scan() {
           // scan disk
           for (MyTestCase t : tests) { addTest(t); }
       }
  }
  
  @RunWith(PowerMockRunner.class)
  @PrepareForTest(ClassToStub.class)
  public class MyTestCase extends TestCase {
       public MyTestCase(TestInfo info) {...}
  
       @Override
       protected void setUp() throws Exception {
           PowerMockito.mockStatic(ClassToStub.class);
           when(ClassToStub.methodToStub())
                  .thenReturn(new FakeProxy());
       }
       @Test
       public void test() throws Exception {
           // Test!
       }
  }
  </code></pre>
  
  <p>Above code seems not working:</p>
  
  <blockquote>
    <p>Also, this error might show up because:
    1. you stub either of: final/private/equals()/hashCode() methods.
       Those methods <em>cannot</em> be stubbed/verified.
    2. inside when() you don't call method on mock but on some other object.
    3. the parent of the mocked class is not public.
       It is a limitation of the mock engine.</p>
  </blockquote>
  
  <p>I traced the code and found that PowerMockRunner are not called at all.
  Also I tried manually force Junit to run it with PowerMockRunner:</p>
  
  <pre><code>Result result = junit.run(new PowerMockRunner(MyTestCase.class));
  </code></pre>
  
  <p>PowerMockRunner has only one constructor that takes the test class as parameter. My test cases are different each time but all share the same class.</p>
  
  <p>Any idea how to use PowerMock if TestCase are dynamically created?
  I was using Junit 4 / PowerMock 1.5</p>