【发布时间】:2020-04-05 06:51:31
【问题描述】:
我将不胜感激有关为什么在以下 Junit5 测试套件中跳过 @BeforeAll 的任何提示。仅供参考,我使用 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);
}
}
【问题讨论】:
-
您是如何得出
BeforeAll未运行的结论的?测试运行时cDao是否为空? -
有
@RunWith(JUnitPlatform.class)还是没有? -
@user7,是的,它是空的。另外,我可以从日志输出中看出。
-
@DanyalSandeelo,不,我没有使用该注释。我会试试看——也许会有帮助。
-
@benthumb 我已将其添加到我的答案中。
标签: java maven junit5 maven-archetype java-annotations