首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在JunitPerf中使用@BeforeClass和@AfterClass?

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

Stack Overflow用户
提问于 2010-04-30 01:07:12
回答 1查看 1.1K关注 0票数 0

我想在整个测试套件之前(也在套件之后)执行一些操作。所以我这样写道:

代码语言:javascript
复制
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中的代码。那么我该如何解决这个问题呢?或者有其他方法来实现这一点吗?谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-04-30 01:52:56

您不能同时扩展TestCase和使用注释。

TestCase是JUnit 3的概念,批注是JUnit 4的概念。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2739302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档