如何在JunitPerf中使用@BeforeClass和@AfterClass?
我想在整个测试套件之前(也在套件之后)执行一些操作。所以我这样写:
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中的代码。 那么我该如何解决这个问题呢?或者还有其他方法可以实现这一点吗? 感谢您的帮助。
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.
So how could I do to solve this problem? Or is there other way to realize this?
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能在扩展 TestCase 的同时使用注释。
TestCase 是 JUnit 3 概念,注释是 JUnit 4 概念。
You cannot extend TestCase and use annotations at the same time.
TestCase is a JUnit 3 concept and annotations are a JUnit 4 concept.