如何在junit4中調用其他類的靜態方法@Before
或@Test
?junit4:如何在junit4 @before或@Test中調用其他類的靜態方法?
我有一個關於如何在junit4 @Test
或@Before
中調用其他類方法的問題?
例如,我在UtilTool
寫了static
方法
public static String readAllBytes(String filePath) {
String content = "";
try {
content = new String(Files.readAllBytes(Paths.get(filePath)));
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
使用在junit4 @Before
的定義方法:
@Before
public void setUp() {
System.out.println("setUp......");
UtilTool.readAllBytes("/tmp/test.txt")
不過,我會收到以下錯誤消息時我稱之爲readAllBytes
方法從Junit4的UtilTool
@Before
或@Test
java.lang.NoSuchMethodError: .....
我該如何解決這個問題?
這看起來像一個編譯問題給我。你如何建立/運行你的測試? Maven的? –
我只是想法編譯我的項目,我不使用maven。 – sagr
如果我在Junit Test類中聲明readAllBytes方法,它將會正常工作。 – sagr