TestNG在另一个包中注释了超类

时间:2012-02-17 21:54:20

标签: testng

我在不同的包中有一个超类和一个子类。超类具有@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");
}
}

这是设计吗?

1 个答案:

答案 0 :(得分:0)

不,它应该有用,它对我有用:

Inside prepareDataSet
Insde beforeTestMethod yy

===============================================
SingleSuite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

您可能省略了一些信息。