我在不同的包中有一个超类和一个子类。超类具有@BeforeClass
和@BeforeMethod
注释。
然而,这些方法永远不会被调用。如果我将两个类都移动到一个公共包中,那么两个@Before_xx
方法都会被调用。
超级课程:
package com.blah.focus.test.integration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
public class BookSuper {
@BeforeClass(groups = "unit")
void prepareDataSet() throws Exception {
System.out.println("Inside prepareDataSet");
}
/**
*
* @throws Exception
*/
@BeforeMethod(groups = "unit")
void beforeTestMethod() throws Exception {
System.out.println("Insde beforeTestMethod yy");
}
}
子类:
package com.blah.focus.domain;
public class BookTest extends BookSuper{
private Book book;
@Test(groups = "unit")
public void testGoodBookConstruction() {
book = new Book();
book.setAuthor("Henry");
book.setTitle("Good Title");
book.setPublished(new Date());
book.setPublisher("Rodale");
}
}
这是设计吗?
答案 0 :(得分:0)
不,它应该有用,它对我有用:
Inside prepareDataSet
Insde beforeTestMethod yy
===============================================
SingleSuite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
您可能省略了一些信息。