开发者

How to use @BeforeClass and @AfterClass in JunitPerf?

开发者 https://www.devze.com 2022-12-29 03:46 出处:网络
I want to do some actions before the whole test suite (also after the suite). So I wrote like: public class PerformanceTest extends TestCase {

I want to do some actions before the whole test suite (also after the suite). So I wrote like:

public class PerformanceTest extends TestCase {

    @BeforeClass
    public static void suiteSetup() throws Exception {
   开发者_StackOverflow       //do something
    }

    @AfterClass
    public static void suiteSetup() throws Exception {
          //do something
    }

    @Before
    public void setUp()  throws Exception {
          //do something
    }

    @After
    public void tearDown()  throws Exception {
          //do something
    }

    public PerformanceTest(String testName){
          super(testName);
    }

    public static Test suite() {
          TestSuite suite = new TestSuite();

          Test testcase1 = new PerformanceTest("DoTest1");
          Test loadTest1 = new LoadTest(testcase1, n);

          Test testcase2 = new PerformanceTest("DoTest2");
          Test loadTest2 = new LoadTest(testcase2, n);

          return suite;
    }

    public void DoTest1 throws Throwable{
          //do something
    }

    public void DoTest2 throws Throwable{
          //do something
    }
}

But I found that it never reach the code in @BeforeClass and @AfterClass. So how could I do to solve this problem? Or is there other way to realize this? Thank you for your help.


You cannot extend TestCase and use annotations at the same time.

TestCase is a JUnit 3 concept and annotations are a JUnit 4 concept.

0

精彩评论

暂无评论...
验证码 换一张
取 消