title: About TestNG @BeforeClass in multi@Test situation
body: <p>I put initMocks and some PowerMockito init(each PowerMockito.when point to each @Test) in @BeforeClass.</p>
  
  <p>But when run as TestNG test, just one @Test is success, the others is fail because these PowerMockito seems don't work.</p>
  
  <p>Here is test code. </p>
  
  <pre><code>package main.test.testng.biz;
  
  import main.java.testng.biz.Clazzname;
  import main.java.testng.dao.Dao1;
  import main.java.testng.dao.Dao2;
  import main.java.testng.dao.Dao3;
  
  import org.mockito.Mock;
  import org.mockito.MockitoAnnotations;
  import org.powermock.api.mockito.PowerMockito;
  import org.powermock.core.classloader.annotations.PrepareForTest;
  import org.powermock.modules.junit4.PowerMockRunner;
  import org.powermock.modules.testng.PowerMockTestCase;
  import org.testng.annotations.BeforeClass;
  import org.testng.annotations.BeforeMethod;
  import org.testng.annotations.Test;
  import org.junit.runner.RunWith;
  
  @RunWith(PowerMockRunner.class)
  @PrepareForTest(Clazzname.class)
  public class TestClazzname extends PowerMockTestCase {
      private Clazzname demo;
      @Mock
      private Dao1 dao1;
      @Mock
      private Dao2 dao2;
      @Mock
      private Dao3 dao3;
  
      @BeforeClass
      private void beforeClass() throws Exception {
          MockitoAnnotations.initMocks(this);
  
          PowerMockito.whenNew(Dao1.class).withNoArguments().thenReturn(dao1);
          PowerMockito.doNothing().when(dao1).set();
          PowerMockito.whenNew(Dao2.class).withNoArguments().thenReturn(dao2);
          PowerMockito.doNothing().when(dao2).set();
          PowerMockito.whenNew(Dao3.class).withNoArguments().thenReturn(dao3);
          PowerMockito.doNothing().when(dao3).set();
      }
  
      @BeforeMethod
      public void beforeMethod() throws Exception {
          demo = new Clazzname();
      }
  
      @Test
      public void test1() throws Exception {
          demo.test1();
      }
  
      @Test
      public void test2() throws Exception {
          demo.test2();
      }
  
      @Test
      public void test3() throws Exception {
          demo.test3();
      }
  }
  </code></pre>
  
  <p>Here is tested code.</p>
  
  <pre><code>package main.java.testng.biz;
  
  import main.java.testng.dao.Dao1;
  import main.java.testng.dao.Dao2;
  import main.java.testng.dao.Dao3;
  
  public class Clazzname {
      public void test1() throws Exception {
          System.out.println("test1");
          new Dao1().set();
      }
  
      public void test2() throws Exception {
          System.out.println("test2");
          new Dao2().set();
      }
  
      public void test3() throws Exception {
          System.out.println("test3");
          new Dao3().set();
      }
  }
  </code></pre>
  
  <p>Here is class which invoked by tested code.</p>
  
  <pre><code>package main.java.testng.dao;
  
  public class Dao1 {
      public void set() throws Exception {
          throw new Exception();
      }
  }
  </code></pre>
  
  <p>Here is class which invoked by tested code.</p>
  
  <pre><code>package main.java.testng.dao;
  
  public class Dao2 {
      public void set() throws Exception {
          throw new Exception();
      }
  }
  </code></pre>
  
  <p>Here is class which invoked by tested code.</p>
  
  <pre><code>package main.java.testng.dao;
  
  public class Dao3 {
      public void set() throws Exception {
          throw new Exception();
      }
  }
  </code></pre>
  
  <p>Here is result.</p>
  
  <pre><code>test1
  test2
  test3
  PASSED: test1
  FAILED: test2
  FAILED: test3
  </code></pre>
  
  <p>Do anyone know the reason?</p>