我有一個小型的java項目,我使用TestNG + Eclipse執行,並且運行良好。 使用屬性我已經外化的測試數據文件,我在我的測試類的一個靜態塊初始化 -屬性文件的靜態初始化失敗,並生成ant
public class SanityTest extends SelTestCase {
static Properties properties = new Properties();
static String pickUp;
static String dropOff;
static {
try {
properties
.load(SanityTest.class
.getResourceAsStream("/com/product/testdata/testdata.properties"));
pickUp = properties.getProperty("pickUp");
dropOff = properties.getProperty("dropOff");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Verifies the booking of car on car hire market
* @throws Exception
*/
@Test
public void testBookingModule() throws Exception {
// Some tests here
}
但是,當我使用Ant構建(1.8)我碰到下面的目標異常「運行」執行相同的 -
[testng] Caused by: java.lang.NullPointerException
[testng] at java.util.Properties$LineReader.readLine(Properties.java:418)
[testng] at java.util.Properties.load0(Properties.java:337)
[testng] at java.util.Properties.load(Properties.java:325)
我找不出多少,並檢查「bin」是否已創建並具有所有相應的文件。 有沒有我錯過的東西?
你是如何格式化你的prop文件的內容的? – karla