简体   繁体   English

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

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

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 {
          //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. 但是我发现它永远无法到达@BeforeClass和@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和使用批注。

TestCase is a JUnit 3 concept and annotations are a JUnit 4 concept. TestCase是一个JUnit 3概念,而注释是一个JUnit 4概念。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在JerseyTest套件中使用@BeforeClass和@AfterClass - How to use @BeforeClass and @AfterClass within a JerseyTest suite @BeforeClass 和@AfterClass 方法没有被执行 - @BeforeClass and @AfterClass methodis not executed 如何在Junit3中获得@BeforeClass和@AfterClass等价物? - How can I get @BeforeClass and @AfterClass equivalent in Junit3? 如何在TestSuite界面中使用junit @Beforeclass && @Afterclass? - How can I have a junit @Beforeclass && @Afterclass in my TestSuite interface? 如何使用TestNG在循环中运行@beforeclass @test和@Afterclass案例 - How to run @beforeclass @test and @Afterclass cases in a loop using TestNG 如何要求JUnit测试实现@ BeforeClass / @ AfterClass“抽象方法”? - How to require that JUnit tests implement a @BeforeClass/@AfterClass “abstract method”? 如何将JUnitPerf与JWebUnit和JUnit 4一起使用? - How do I use JUnitPerf with JWebUnit and JUnit 4? 将参数传递给@BeforeClass和@AfterClass方法 - Passing params to @BeforeClass and @AfterClass methods 如何使用静态@AfterClass 注入 - How to use injection with static @AfterClass 使用Failsafe + Cucumber Parallel插件时无法使用@BeforeClass @AfterClass等Junit或TestNG注释 - Not able to use Junit or TestNG Annotations like @BeforeClass @AfterClass while using Failsafe + Cucumber Parallel plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM