Junit5和Maven:@BeforeAll初始化方法未调用

问题描述 投票:0回答:1

我希望在以下Junit5测试套件中跳过@BeforeAll的任何提示。仅供参考,我使用Maven构建时的输出:


T E S T S

14:43:53.681 [main]调试org.benthumb.db2_web_app.tests.CustomerDaoTest-创建测试对象...运行org.benthumb.db2_web_app.tests.CustomerDaoTest

14:43:53.689 [main]调试org.benthumb.db2_web_app.tests.CustomerDaoTest-测试一个正在执行的...

14:43:53.696 [main]调试org.benthumb.db2_web_app.tests.CustomerDaoTest-客户访问对象为空...测试运行:2,失败:0,错误:0,跳过:0,经过的时间:0.005秒

public class CustomerDaoTest {

private static CustomerDao cDao;
private static Customer cust;
private static Properties props;
private final static String PROP_FILE_NAME = "customer.properties";
private static InputStream is;
final static Logger logger = LoggerFactory.getLogger(CustomerDaoTest.class);

public CustomerDaoTest() {
    logger.debug("creating test object...");
    is = getClass().getClassLoader().getResourceAsStream(PROP_FILE_NAME);
}

@BeforeAll
public static void initializeTestConditions() throws IOException {
    logger.debug("setting up customer access object...");
    props = new Properties();
    if (is != null) {
        props.load(is);
    } else {
        throw new FileNotFoundException("property file '" + PROP_FILE_NAME + "' not found in the classpath");
    }

    cust = new Customer(
            props.getProperty("id"),
            props.getProperty("businessName"),
            props.getProperty("jobTitle"),
            props.getProperty("firstName"),
            props.getProperty("address"),
            props.getProperty("address2"),
            "",
            props.getProperty("city"),
            props.getProperty("state"),
            props.getProperty("country"),
            props.getProperty("phone")
    );
    cDao = new CustomerDao();
    //conn = cDao.conn;
}

@Test
public void testConnectionCustomerDao() throws SQLException {
    //Properties prop = conn.getClientInfo();
    //assertEquals("these two values are equal", prop, null);
    logger.debug("test one executing...");
    Assumptions.assumeTrue(1 == 1);
}

@Test
public void testPersistCustomerDao() {
    if (cDao != null) {
        try {
            cDao.addCustomer(cust);
        } catch (SQLException ex) {
            logger.error(Marker.ANY_MARKER, null, ex.getErrorCode());
        }
    } else {
        logger.debug("customer access object is null...");
    }
    Assumptions.assumeTrue(1 == 1);
}

}

java maven junit5 maven-archetype java-annotations
1个回答
0
投票

您的课程没有@RunWith(JUnitPlatform.class)批注。添加它,它将正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.