我想在整个测试套件之前(也在套件之后)执行一些操作。所以我这样写道:
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中的代码。那么我该如何解决这个问题呢?或者有其他方法来实现这一点吗?谢谢你的帮助。
发布于 2010-04-30 01:52:56
您不能同时扩展TestCase和使用注释。
TestCase是JUnit 3的概念,批注是JUnit 4的概念。
https://stackoverflow.com/questions/2739302
复制相似问题