[英]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.