簡體   English   中英

如何在JunitPerf中使用@BeforeClass和@AfterClass?

[英]How to use @BeforeClass and @AfterClass in JunitPerf?

我想在整個測試套件之前(在套件之后)執行一些操作。 所以我這樣寫:

public class PerformanceTest extends TestCase {

    @BeforeClass
    public static void suiteSetup() throws Exception {
          //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
    }
}

但是我發現它永遠無法到達@BeforeClass和@AfterClass中的代碼。 那么我該怎么做才能解決這個問題呢? 還是有其他方法可以實現這一目標? 謝謝您的幫助。

您不能同時擴展TestCase和使用批注。

TestCase是一個JUnit 3概念,而注釋是一個JUnit 4概念。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM