Junit5和Maven:@BeforeAll初始化方法不会被调用

benthumb:

我将不胜感激任何提示,为什么@BeforeAll下面的Junit5测试套件被跳过。仅供参考,我的输出,当我用Maven构建:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

14:43:53.681 [main] DEBUG org.benthumb.db2_web_app.tests.CustomerDaoTest - creating test object...
Running org.benthumb.db2_web_app.tests.CustomerDaoTest

14:43:53.689 [main] DEBUG org.benthumb.db2_web_app.tests.CustomerDaoTest - test one executing...

14:43:53.696 [main] DEBUG org.benthumb.db2_web_app.tests.CustomerDaoTest - customer access object is null...
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 sec

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);
    }

}
Danyal Sandeelo:

您的类没有@RunWith(JUnitPlatform.class)注解。添加它,它会正常工作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在CBCentralManager初始化centralManagerDidUpdateState之后,它不会被调用

在测试JUnit5和Spring之前先初始化数据库

Maven不会运行JUnit5测试

未初始化的TypeScript类属性不会被迭代

数据成员即使被初始化也不会被初始化

Junit5 参数化测试生命周期。为什么 @BeforeAll 和 static 块在所有测试之后运行

将Spring @Value传递给静态@BeforeAll Junit5方法

初始化和调用变量

Junit会在每次测试方法调用时重新初始化类吗?

JUnit:是否可以模拟在全局变量的初始化中调用的静态方法?

为JUnit 4/5创建注释以在测试中初始化和注入对象

BeanCreationException:初始化方法的调用失败

正确的Rails初始化方法调用

初始化对象时调用方法

通过调用方法初始化数组

从Swift初始化程序调用方法

从父构造函数调用的重写方法不会初始化字段

在JUnit 5中参数化beforeEach / beforeAll

在 dataTable ajax 请求期间,隐藏的表单控件永远不会被初始化

错误:“物业‘self.gameArea’在super.init通话不会被初始化”

NSFetchedResultsControllerDelegate方法不会被调用

从应用程序调用时CEFPython不会初始化

关机时不会调用初始化脚本

accept()调用不会初始化sockaddr结构

每次调用函数时,函数内部的变量是否都会被销毁并重新初始化?

Hashmap的containsKey方法是否是线程安全的,如果该映射被初始化一次,并且再也不会被修改

依赖注入和初始化方法

Facebook SDK和WebPlayer。初始化不会回调

Junit引发初始化错误。找不到方法“ com”